MCPcopy Create free account
hub / github.com/charmbracelet/log / Write

Method Write

stdlog.go:13–45  ·  view source on GitHub ↗
(p []byte)

Source from the content-addressed store, hash-verified

11}
12
13func (l *stdLogWriter) Write(p []byte) (n int, err error) {
14 str := strings.TrimSuffix(string(p), "\n")
15
16 if l.opt != nil {
17 switch l.opt.ForceLevel { //nolint:exhaustive
18 case DebugLevel:
19 l.l.Debug(str)
20 case InfoLevel:
21 l.l.Info(str)
22 case WarnLevel:
23 l.l.Warn(str)
24 case ErrorLevel:
25 l.l.Error(str)
26 }
27 } else {
28 switch {
29 case strings.HasPrefix(str, "DEBUG"):
30 l.l.Debug(strings.TrimSpace(str[5:]))
31 case strings.HasPrefix(str, "INFO"):
32 l.l.Info(strings.TrimSpace(str[4:]))
33 case strings.HasPrefix(str, "WARN"):
34 l.l.Warn(strings.TrimSpace(str[4:]))
35 case strings.HasPrefix(str, "ERROR"):
36 l.l.Error(strings.TrimSpace(str[5:]))
37 case strings.HasPrefix(str, "ERR"):
38 l.l.Error(strings.TrimSpace(str[3:]))
39 default:
40 l.l.Info(str)
41 }
42 }
43
44 return len(p), nil
45}
46
47// StandardLogOptions can be used to configure the standard log adapter.
48type StandardLogOptions struct {

Callers 3

writeIndentMethod · 0.80
writeSpaceFunction · 0.80
TestRaceFunction · 0.80

Calls 4

DebugMethod · 0.80
InfoMethod · 0.80
WarnMethod · 0.80
ErrorMethod · 0.80

Tested by 1

TestRaceFunction · 0.64