MCPcopy Create free account
hub / github.com/ethstorage/es-node / NewLogger

Function NewLogger

ethstorage/log/logger.go:16–47  ·  view source on GitHub ↗
(cfg CLIConfig)

Source from the content-addressed store, hash-verified

14)
15
16func NewLogger(cfg CLIConfig) log.Logger {
17 l, err := levelFromString(cfg.Level)
18 if err != nil {
19 panic(err)
20 }
21
22 // Select output (enable Windows color support if needed)
23 output := io.Writer(os.Stdout)
24 useColor := cfg.Color && (isatty.IsTerminal(os.Stdout.Fd()) || isatty.IsCygwinTerminal(os.Stdout.Fd())) && os.Getenv("TERM") != "dumb"
25
26 // Enable cross-platform color support for Windows terminals using go-colorable wrapper
27 if useColor {
28 output = colorable.NewColorableStdout()
29 }
30
31 var h slog.Handler
32 switch cfg.Format {
33 case "terminal":
34 // Terminal format with timestamp and optional colors
35 h = log.NewTerminalHandlerWithLevel(output, l, useColor)
36 case "text", "logfmt":
37 // slog text handler is logfmt-like: key=value pairs per line
38 h = slog.NewTextHandler(output, &slog.HandlerOptions{Level: l})
39 case "json", "json-pretty":
40 // Pretty JSON is not natively supported; fall back to compact JSON
41 h = slog.NewJSONHandler(output, &slog.HandlerOptions{Level: l})
42 default:
43 h = log.NewTerminalHandlerWithLevel(output, l, useColor)
44 }
45
46 return log.NewLogger(h)
47}
48
49func DefaultLogger() log.Logger {
50 return NewLogger(defaultCLIConfig)

Callers 3

blob_cache_test.goFile · 0.92
EsNodeMainFunction · 0.92
DefaultLoggerFunction · 0.85

Calls 1

levelFromStringFunction · 0.85

Tested by

no test coverage detected