mirror of
https://github.com/SagerNet/sing-box.git
synced 2024-11-25 10:01:30 +00:00
Apply --disable-color
to global logger
This commit is contained in:
parent
7d22cf9b45
commit
caad60da45
|
@ -2,6 +2,7 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
"time"
|
||||||
|
|
||||||
_ "github.com/sagernet/sing-box/include"
|
_ "github.com/sagernet/sing-box/include"
|
||||||
"github.com/sagernet/sing-box/log"
|
"github.com/sagernet/sing-box/log"
|
||||||
|
@ -33,6 +34,9 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func preRun(cmd *cobra.Command, args []string) {
|
func preRun(cmd *cobra.Command, args []string) {
|
||||||
|
if disableColor {
|
||||||
|
log.SetStdLogger(log.NewFactory(log.Formatter{BaseTime: time.Now(), DisableColors: true}, os.Stderr, nil).Logger())
|
||||||
|
}
|
||||||
if workingDir != "" {
|
if workingDir != "" {
|
||||||
if err := os.Chdir(workingDir); err != nil {
|
if err := os.Chdir(workingDir); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
|
|
|
@ -16,6 +16,10 @@ func StdLogger() ContextLogger {
|
||||||
return std
|
return std
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func SetStdLogger(logger ContextLogger) {
|
||||||
|
std = logger
|
||||||
|
}
|
||||||
|
|
||||||
func Trace(args ...any) {
|
func Trace(args ...any) {
|
||||||
std.Trace(args...)
|
std.Trace(args...)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,15 @@
|
||||||
package log
|
package log
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"github.com/sagernet/sing/common/logger"
|
||||||
|
|
||||||
"github.com/sagernet/sing/common/observable"
|
"github.com/sagernet/sing/common/observable"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type (
|
||||||
|
Logger logger.Logger
|
||||||
|
ContextLogger logger.ContextLogger
|
||||||
|
)
|
||||||
|
|
||||||
type Factory interface {
|
type Factory interface {
|
||||||
Level() Level
|
Level() Level
|
||||||
SetLevel(level Level)
|
SetLevel(level Level)
|
||||||
|
@ -22,24 +26,3 @@ type Entry struct {
|
||||||
Level Level
|
Level Level
|
||||||
Message string
|
Message string
|
||||||
}
|
}
|
||||||
|
|
||||||
type Logger interface {
|
|
||||||
Trace(args ...any)
|
|
||||||
Debug(args ...any)
|
|
||||||
Info(args ...any)
|
|
||||||
Warn(args ...any)
|
|
||||||
Error(args ...any)
|
|
||||||
Fatal(args ...any)
|
|
||||||
Panic(args ...any)
|
|
||||||
}
|
|
||||||
|
|
||||||
type ContextLogger interface {
|
|
||||||
Logger
|
|
||||||
TraceContext(ctx context.Context, args ...any)
|
|
||||||
DebugContext(ctx context.Context, args ...any)
|
|
||||||
InfoContext(ctx context.Context, args ...any)
|
|
||||||
WarnContext(ctx context.Context, args ...any)
|
|
||||||
ErrorContext(ctx context.Context, args ...any)
|
|
||||||
FatalContext(ctx context.Context, args ...any)
|
|
||||||
PanicContext(ctx context.Context, args ...any)
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue