<commit_before>package log

import (
	"fmt"

	"github.com/v2ray/v2ray-core/common"
	"github.com/v2ray/v2ray-core/common/alloc"
	"github.com/v2ray/v2ray-core/common/serial"
)

const (
	DebugLevel   = LogLevel(0)
	InfoLevel    = LogLevel(1)
	WarningLevel = LogLevel(2)
	ErrorLevel   = LogLevel(3)
	NoneLevel    = LogLevel(999)
)

type LogEntry interface {
	common.Releasable
	serial.String
}

type errorLog struct {
	prefix string
	values []interface{}
}

func (this *errorLog) Release() {
	for index := range this.values {
		this.values[index] = nil
	}
	this.values = nil
}

func (this *errorLog) String() string {
	b := alloc.NewSmallBuffer().Clear()
	defer b.Release()

	b.AppendString(this.prefix)

	for _, value := range this.values {
		switch typedVal := value.(type) {
		case string:
			b.AppendString(typedVal)
		case *string:
			b.AppendString(*typedVal)
		case serial.String:
			b.AppendString(typedVal.String())
		case error:
			b.AppendString(typedVal.Error())
		default:
			b.AppendString(fmt.Sprint(value))
		}
	}
	return b.String()
}

var (
	noOpLoggerInstance   logWriter = &noOpLogWriter{}
	streamLoggerInstance logWriter = newStdOutLogWriter()

	debugLogger   = noOpLoggerInstance
	infoLogger    = noOpLoggerInstance
	warningLogger = streamLoggerInstance
	errorLogger   = streamLoggerInstance
)

type LogLevel int

func SetLogLevel(level LogLevel) {
	debugLogger = noOpLoggerInstance
	if level <= DebugLevel {
		debugLogger = streamLoggerInstance
	}

	infoLogger = noOpLoggerInstance
	if level <= InfoLevel {
		infoLogger = streamLoggerInstance
	}

	warningLogger = noOpLoggerInstance
	if level <= WarningLevel {
		warningLogger = streamLoggerInstance
	}

	errorLogger = noOpLoggerInstance
	if level <= ErrorLevel {
		errorLogger = streamLoggerInstance
	}<commit_msg>disable access log if log level = none<commit_after>package log

import (
	"fmt"

	"github.com/v2ray/v2ray-core/common"
	"github.com/v2ray/v2ray-core/common/alloc"
	"github.com/v2ray/v2ray-core/common/serial"
)

const (
	DebugLevel   = LogLevel(0)
	InfoLevel    = LogLevel(1)
	WarningLevel = LogLevel(2)
	ErrorLevel   = LogLevel(3)
	NoneLevel    = LogLevel(999)
)

type LogEntry interface {
	common.Releasable
	serial.String
}

type errorLog struct {
	prefix string
	values []interface{}
}

func (this *errorLog) Release() {
	for index := range this.values {
		this.values[index] = nil
	}
	this.values = nil
}

func (this *errorLog) String() string {
	b := alloc.NewSmallBuffer().Clear()
	defer b.Release()

	b.AppendString(this.prefix)

	for _, value := range this.values {
		switch typedVal := value.(type) {
		case string:
			b.AppendString(typedVal)
		case *string:
			b.AppendString(*typedVal)
		case serial.String:
			b.AppendString(typedVal.String())
		case error:
			b.AppendString(typedVal.Error())
		default:
			b.AppendString(fmt.Sprint(value))
		}
	}
	return b.String()
}

var (
	noOpLoggerInstance   logWriter = &noOpLogWriter{}
	streamLoggerInstance logWriter = newStdOutLogWriter()

	debugLogger   = noOpLoggerInstance
	infoLogger    = noOpLoggerInstance
	warningLogger = streamLoggerInstance
	errorLogger   = streamLoggerInstance
)

type LogLevel int

func SetLogLevel(level LogLevel) {
	debugLogger = noOpLoggerInstance
	if level <= DebugLevel {
		debugLogger = streamLoggerInstance
	}

	infoLogger = noOpLoggerInstance
	if level <= InfoLevel {
		infoLogger = streamLoggerInstance
	}

	warningLogger = noOpLoggerInstance
	if level <= WarningLevel {
		warningLogger = streamLoggerInstance
	}

	errorLogger = noOpLoggerInstance
	if level <= ErrorLevel {
		errorLogger = streamLoggerInstance
	}

	if level == NoneLevel {
		accessLoggerInstance = noOpLoggerInstance
	}
{'fraction_non_alphanumeric': 0.10262008733624454, 'fraction_numerical': 0.007096069868995633, 'mean_word_length': 4.296242774566474, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 3, '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': '6565795', 'n_tokens_mistral': 1291, 'n_tokens_neox': 1223, 'n_words': 259}