mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-01-21 16:56:27 -05:00
Merge branch 'master' of https://github.com/v2ray/v2ray-core
This commit is contained in:
commit
056084defd
@ -13,11 +13,11 @@ type LogEntry interface {
|
||||
|
||||
type ErrorLog struct {
|
||||
Prefix string
|
||||
Values []interface{}
|
||||
Error error
|
||||
}
|
||||
|
||||
func (v *ErrorLog) String() string {
|
||||
return v.Prefix + serial.Concat(v.Values...)
|
||||
return v.Prefix + v.Error.Error()
|
||||
}
|
||||
|
||||
type AccessLog struct {
|
||||
|
@ -51,54 +51,30 @@ func InitErrorLogger(file string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// writeDebug outputs a debug log with given format and optional arguments.
|
||||
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)
|
||||
func getLoggerAndPrefix(s errors.Severity) (internal.LogWriter, string) {
|
||||
switch s {
|
||||
case errors.SeverityDebug:
|
||||
writeDebug(err)
|
||||
return debugLogger, "[Debug]"
|
||||
case errors.SeverityInfo:
|
||||
writeInfo(err)
|
||||
return infoLogger, "[Info]"
|
||||
case errors.SeverityWarning:
|
||||
writeWarning(err)
|
||||
return infoLogger, "[Warning]"
|
||||
case errors.SeverityError:
|
||||
writeError(err)
|
||||
return errorLogger, "[Error]"
|
||||
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 {
|
||||
config *Config
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import (
|
||||
"v2ray.com/core/common/serial"
|
||||
)
|
||||
|
||||
// Severity describes how severe the error is.
|
||||
type Severity int
|
||||
|
||||
const (
|
||||
@ -78,22 +79,27 @@ func (v *Error) Severity() Severity {
|
||||
return v.severity
|
||||
}
|
||||
|
||||
// AtDebug sets the severity to debug.
|
||||
func (v *Error) AtDebug() *Error {
|
||||
return v.atSeverity(SeverityDebug)
|
||||
}
|
||||
|
||||
// AtInfo sets the severity to info.
|
||||
func (v *Error) AtInfo() *Error {
|
||||
return v.atSeverity(SeverityInfo)
|
||||
}
|
||||
|
||||
// AtWarning sets the severity to warning.
|
||||
func (v *Error) AtWarning() *Error {
|
||||
return v.atSeverity(SeverityWarning)
|
||||
}
|
||||
|
||||
// AtError sets the severity to error.
|
||||
func (v *Error) AtError() *Error {
|
||||
return v.atSeverity(SeverityError)
|
||||
}
|
||||
|
||||
// Path sets the path to the location where this error happens.
|
||||
func (v *Error) Path(path ...string) *Error {
|
||||
v.path = path
|
||||
return v
|
||||
|
Loading…
Reference in New Issue
Block a user