1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-17 18:06:15 -05:00
v2fly/common/log/log.go

84 lines
1.9 KiB
Go
Raw Normal View History

package log
import (
2016-12-04 03:10:47 -05:00
"v2ray.com/core/common/errors"
2016-08-20 14:55:45 -04:00
"v2ray.com/core/common/log/internal"
)
var (
2016-05-12 02:24:41 -04:00
streamLoggerInstance internal.LogWriter = internal.NewStdOutLogWriter()
2016-05-12 02:24:41 -04:00
debugLogger internal.LogWriter = streamLoggerInstance
infoLogger internal.LogWriter = streamLoggerInstance
warningLogger internal.LogWriter = streamLoggerInstance
errorLogger internal.LogWriter = streamLoggerInstance
)
func SetLogLevel(level LogLevel) {
2016-05-12 02:24:41 -04:00
debugLogger = new(internal.NoOpLogWriter)
2016-10-03 16:07:28 -04:00
if level >= LogLevel_Debug {
debugLogger = streamLoggerInstance
}
2016-05-12 02:24:41 -04:00
infoLogger = new(internal.NoOpLogWriter)
2016-10-03 16:07:28 -04:00
if level >= LogLevel_Info {
infoLogger = streamLoggerInstance
}
2016-05-12 02:24:41 -04:00
warningLogger = new(internal.NoOpLogWriter)
2016-10-03 16:07:28 -04:00
if level >= LogLevel_Warning {
warningLogger = streamLoggerInstance
}
2016-05-12 02:24:41 -04:00
errorLogger = new(internal.NoOpLogWriter)
2016-10-03 16:07:28 -04:00
if level >= LogLevel_Error {
errorLogger = streamLoggerInstance
}
}
2015-12-05 15:10:14 -05:00
func InitErrorLogger(file string) error {
2016-05-12 02:24:41 -04:00
logger, err := internal.NewFileLogWriter(file)
2015-12-05 15:10:14 -05:00
if err != nil {
2016-12-04 03:10:47 -05:00
return errors.Base(err).Message("Log: Failed to create error logger on file (", file, ")")
2015-12-05 15:10:14 -05:00
}
streamLoggerInstance = logger
return nil
}
2015-10-15 07:15:59 -04:00
// Debug outputs a debug log with given format and optional arguments.
2016-11-27 11:01:44 -05:00
func Debug(val ...interface{}) {
2016-05-12 02:24:41 -04:00
debugLogger.Log(&internal.ErrorLog{
Prefix: "[Debug]",
2016-11-27 11:01:44 -05:00
Values: val,
2015-12-05 15:10:14 -05:00
})
2015-09-12 05:51:42 -04:00
}
2015-10-15 07:15:59 -04:00
// Info outputs an info log with given format and optional arguments.
2016-11-27 11:01:44 -05:00
func Info(val ...interface{}) {
2016-05-12 02:24:41 -04:00
infoLogger.Log(&internal.ErrorLog{
Prefix: "[Info]",
2016-11-27 11:01:44 -05:00
Values: val,
2015-12-05 15:10:14 -05:00
})
}
2015-10-15 07:15:59 -04:00
// Warning outputs a warning log with given format and optional arguments.
2016-11-27 11:01:44 -05:00
func Warning(val ...interface{}) {
2016-05-12 02:24:41 -04:00
warningLogger.Log(&internal.ErrorLog{
Prefix: "[Warning]",
2016-11-27 11:01:44 -05:00
Values: val,
2015-12-05 15:10:14 -05:00
})
}
2015-10-15 07:15:59 -04:00
// Error outputs an error log with given format and optional arguments.
2016-11-27 11:01:44 -05:00
func Error(val ...interface{}) {
2016-05-12 02:24:41 -04:00
errorLogger.Log(&internal.ErrorLog{
Prefix: "[Error]",
2016-11-27 11:01:44 -05:00
Values: val,
2015-12-05 15:10:14 -05:00
})
}
2016-07-10 17:11:42 -04:00
func Close() {
streamLoggerInstance.Close()
accessLoggerInstance.Close()
}