You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
v2ray-core/common/log/log.go

93 lines
2.0 KiB

package log
import (
9 years ago
"github.com/v2ray/v2ray-core/common/log/internal"
)
9 years ago
type LogLevel int
const (
DebugLevel = LogLevel(0)
InfoLevel = LogLevel(1)
WarningLevel = LogLevel(2)
ErrorLevel = LogLevel(3)
9 years ago
NoneLevel = LogLevel(999)
)
var (
9 years ago
streamLoggerInstance internal.LogWriter = internal.NewStdOutLogWriter()
9 years ago
debugLogger internal.LogWriter = streamLoggerInstance
infoLogger internal.LogWriter = streamLoggerInstance
warningLogger internal.LogWriter = streamLoggerInstance
errorLogger internal.LogWriter = streamLoggerInstance
)
func SetLogLevel(level LogLevel) {
9 years ago
debugLogger = new(internal.NoOpLogWriter)
if level <= DebugLevel {
debugLogger = streamLoggerInstance
}
9 years ago
infoLogger = new(internal.NoOpLogWriter)
if level <= InfoLevel {
infoLogger = streamLoggerInstance
}
9 years ago
warningLogger = new(internal.NoOpLogWriter)
if level <= WarningLevel {
warningLogger = streamLoggerInstance
}
9 years ago
errorLogger = new(internal.NoOpLogWriter)
if level <= ErrorLevel {
errorLogger = streamLoggerInstance
}
if level == NoneLevel {
9 years ago
accessLoggerInstance = new(internal.NoOpLogWriter)
}
}
func InitErrorLogger(file string) error {
9 years ago
logger, err := internal.NewFileLogWriter(file)
if err != nil {
Error("Failed to create error logger on file (", file, "): ", err)
return err
}
streamLoggerInstance = logger
return nil
}
9 years ago
// Debug outputs a debug log with given format and optional arguments.
func Debug(v ...interface{}) {
9 years ago
debugLogger.Log(&internal.ErrorLog{
Prefix: "[Debug]",
Values: v,
})
}
9 years ago
// Info outputs an info log with given format and optional arguments.
func Info(v ...interface{}) {
9 years ago
infoLogger.Log(&internal.ErrorLog{
Prefix: "[Info]",
Values: v,
})
}
9 years ago
// Warning outputs a warning log with given format and optional arguments.
func Warning(v ...interface{}) {
9 years ago
warningLogger.Log(&internal.ErrorLog{
Prefix: "[Warning]",
Values: v,
})
}
9 years ago
// Error outputs an error log with given format and optional arguments.
func Error(v ...interface{}) {
9 years ago
errorLogger.Log(&internal.ErrorLog{
Prefix: "[Error]",
Values: v,
})
}