<commit_before>// Packet vlog provides package level verbose logging.
// The actual logging is done with the standard log package.
//
// To define a package level logging variable,
//   var v = vlog.New()
//
// To log a message at INFO level,
//   v.I("a")
//
// The logging level can be set with either the flag -vlog or
// the environment variable GO_VLOG.
//
// The -vlog or GO_VLOG format is,
//  k=v(,k=v)*
//  k can be exact match like "foo/bar" or prefix match like "foo/*".
//  v can be w|i|v1|v2
// Default level can be set with prefix match "*".
package vlog

import (
	"bytes"
	"errors"
	"flag"
	"fmt"
	"log"
	"os"
	"path"
	"runtime"
	"sort"
	"strconv"
	"strings"
	"sync/atomic"
)

//go:generate stringer -type=Level
type Level int32

const (
	v2 Level = -2 + iota
	v1
	info
	warn
)

// W logs warning message.
// If args[0] is a format string, args is formatted with Printf,
// otherwise args is formatted with Println.
func (v *Level) W(args ...interface{}) {
	if *v <= warn {
		lg.Log(Format(args...))
	}
}

// I logs info message.
func (v *Level) I(args ...interface{}) {
	if *v <= info {
		lg.Log(Format(args...))
	}
}

// V1 logs verbose level 1 message.
func (v *Level) V1(args ...interface{}) {
	if *v <= v1 {
		lg.Log(Format(args...))
	}
}

// V2 logs verbose level 2 message.
func (v *Level) V2(args ...interface{}) {
	if *v <= v2 {
		lg.Log(Format(args...))
	}
}

// Vstack logs the message and the stacktrace of this goroutine.
// It is noop when verbose logging is not enabled.
func (v *Level) Vstack(args ...interface{}) {
	if *v >= info {
		return
	}
	s := Format(args...)
	lg.Log(stackTrace(s))
}

// On returns true if the specific verbose level 1-3 is enabled.
func (v *Level) On(l int) bool {
	lv := Level(-l)
	return *v <= lv
}

// Vset sets the verbose logging level.
func (v *Level) Vset(l int) Level {
	lv := Level(-l)
	if lv < v2 || lv >= info {
		lg.Log(Format("invalid verbose level=%d", l))
		return *v
	}
	old := *v
	atomic.StoreInt32((*int32)(v), int32(lv))
	return old
}

// Error returns an error. The message of the error is formatted
// from args. If verbose level 1 is enabled, the error messag includes
// the caller, and if verbose level 2 is enabled, the error message
// includes the call stack.
func (v *Level) Error(args ...interface{}) error {
	return v.newError(Format(args...))
}

// newError is necessary to get the correct call stack
func (v *Level) newError(s string) error {
	switch *v {
	default:
		return errors.New(s)

	case v1:
		_, fn, ln, ok := runtime.Caller(3)
		if !ok {
			return errors.New("???: " + s)
		}
		return errors.New("E[" + fn + ":" + strconv.Itoa(ln) + "]" + s)

	case v2:
		return errors.New(stackTrace(s))
	}
}

func parseLevel(lvs string) Level {
	switch strings.ToLower(lvs) {
	case "2", "v2":
		return v2<commit_msg>fix caller depth; change verbose error format<commit_after>// Packet vlog provides package level verbose logging.
// The actual logging is done with the standard log package.
//
// To define a package level logging variable,
//   var v = vlog.New()
//
// To log a message at INFO level,
//   v.I("a")
//
// The logging level can be set with either the flag -vlog or
// the environment variable GO_VLOG.
//
// The -vlog or GO_VLOG format is,
//  k=v(,k=v)*
//  k can be exact match like "foo/bar" or prefix match like "foo/*".
//  v can be w|i|v1|v2
// Default level can be set with prefix match "*".
package vlog

import (
	"bytes"
	"errors"
	"flag"
	"fmt"
	"log"
	"os"
	"path"
	"runtime"
	"sort"
	"strconv"
	"strings"
	"sync/atomic"
)

//go:generate stringer -type=Level
type Level int32

const (
	v2 Level = -2 + iota
	v1
	info
	warn
)

// W logs warning message.
// If args[0] is a format string, args is formatted with Printf,
// otherwise args is formatted with Println.
func (v *Level) W(args ...interface{}) {
	if *v <= warn {
		lg.Log(Format(args...))
	}
}

// I logs info message.
func (v *Level) I(args ...interface{}) {
	if *v <= info {
		lg.Log(Format(args...))
	}
}

// V1 logs verbose level 1 message.
func (v *Level) V1(args ...interface{}) {
	if *v <= v1 {
		lg.Log(Format(args...))
	}
}

// V2 logs verbose level 2 message.
func (v *Level) V2(args ...interface{}) {
	if *v <= v2 {
		lg.Log(Format(args...))
	}
}

// Vstack logs the message and the stacktrace of this goroutine.
// It is noop when verbose logging is not enabled.
func (v *Level) Vstack(args ...interface{}) {
	if *v >= info {
		return
	}
	s := Format(args...)
	lg.Log(stackTrace(s))
}

// On returns true if the specific verbose level 1-3 is enabled.
func (v *Level) On(l int) bool {
	lv := Level(-l)
	return *v <= lv
}

// Vset sets the verbose logging level.
func (v *Level) Vset(l int) Level {
	lv := Level(-l)
	if lv < v2 || lv >= info {
		lg.Log(Format("invalid verbose level=%d", l))
		return *v
	}
	old := *v
	atomic.StoreInt32((*int32)(v), int32(lv))
	return old
}

// Error returns an error. The message of the error is formatted
// from args. If verbose level 1 is enabled, the error messag includes
// the caller, and if verbose level 2 is enabled, the error message
// includes the call stack.
func (v *Level) Error(args ...interface{}) error {
	return v.newError(Format(args...))
}

// newError is necessary to get the correct call stack
func (v *Level) newError(s string) error {
	switch *v {
	default:
		return errors.New(s)

	case v1:
		_, fn, ln, ok := runtime.Caller(2)
		if !ok {
			return errors.New("???: " + s)
		}
		return errors.New(fn + ":" + strconv.Itoa(ln) + " " + s)

	case v2:
		return errors.New(stackTrace(s))
	}
}

func parseLevel(lvs string) Level {
	switch strings.ToLower(lvs) {
	case "2", "v2":
		return v2
{'fraction_non_alphanumeric': 0.15745512706593212, 'fraction_numerical': 0.011729162964279368, 'mean_word_length': 2.957805907172996, 'pattern_counts': {'":': 4, '<': 15, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6447434', 'n_tokens_mistral': 2131, 'n_tokens_neox': 2046, 'n_words': 738}