1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-06-29 02:35:23 +00:00

simplify log handling

This commit is contained in:
Darien Raymond 2017-04-10 15:03:10 +02:00
parent fd0a95e3c6
commit 4fa3c70429
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
2 changed files with 17 additions and 41 deletions

View File

@ -13,11 +13,11 @@ type LogEntry interface {
type ErrorLog struct { type ErrorLog struct {
Prefix string Prefix string
Values []interface{} Error error
} }
func (v *ErrorLog) String() string { func (v *ErrorLog) String() string {
return v.Prefix + serial.Concat(v.Values...) return v.Prefix + v.Error.Error()
} }
type AccessLog struct { type AccessLog struct {

View File

@ -51,54 +51,30 @@ func InitErrorLogger(file string) error {
return nil return nil
} }
// writeDebug outputs a debug log with given format and optional arguments. func getLoggerAndPrefix(s errors.Severity) (internal.LogWriter, string) {
func writeDebug(val ...interface{}) {
debugLogger.Log(&internal.ErrorLog{
Prefix: "[Debug]",
Values: val,
})
}
// writeInfo outputs an info log with given format and optional arguments.
func writeInfo(val ...interface{}) {
infoLogger.Log(&internal.ErrorLog{
Prefix: "[Info]",
Values: val,
})
}
// writeWarning outputs a warning log with given format and optional arguments.
func writeWarning(val ...interface{}) {
warningLogger.Log(&internal.ErrorLog{
Prefix: "[Warning]",
Values: val,
})
}
// writeError outputs an error log with given format and optional arguments.
func writeError(val ...interface{}) {
errorLogger.Log(&internal.ErrorLog{
Prefix: "[Error]",
Values: val,
})
}
func Trace(err error) {
s := errors.GetSeverity(err)
switch s { switch s {
case errors.SeverityDebug: case errors.SeverityDebug:
writeDebug(err) return debugLogger, "[Debug]"
case errors.SeverityInfo: case errors.SeverityInfo:
writeInfo(err) return infoLogger, "[Info]"
case errors.SeverityWarning: case errors.SeverityWarning:
writeWarning(err) return infoLogger, "[Warning]"
case errors.SeverityError: case errors.SeverityError:
writeError(err) return errorLogger, "[Error]"
default: default:
writeInfo(err) return infoLogger, "[Info]"
} }
} }
// Trace logs an error message based on its severity.
func Trace(err error) {
logger, prefix := getLoggerAndPrefix(errors.GetSeverity(err))
logger.Log(&internal.ErrorLog{
Prefix: prefix,
Error: err,
})
}
type Instance struct { type Instance struct {
config *Config config *Config
} }