You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
63 lines
1.3 KiB
63 lines
1.3 KiB
/* |
|
------------------------------------------------------------------------------------------------------------------------ |
|
####### logger ####### Copyright (c) 2021-2022 losyme ############################################## MIT License ####### |
|
------------------------------------------------------------------------------------------------------------------------ |
|
*/ |
|
|
|
package logger |
|
|
|
import ( |
|
"io" |
|
"os" |
|
|
|
"forge.chapril.org/losyme/kvfmt" |
|
) |
|
|
|
type outputStd struct { |
|
io.Writer |
|
} |
|
|
|
func (o *outputStd) Log(l *Log) error { |
|
buf := BufPool.Get() |
|
|
|
buf.AppendString(l.Time.Format("2006-01-02 15:04:05.000000")) |
|
buf.AppendString(" @") |
|
buf.AppendString(l.Level.String()[:3]) |
|
buf.AppendByte(' ') |
|
buf.AppendString(l.Logger.label) |
|
buf.AppendByte(' ') |
|
buf.AppendString(l.Msg) |
|
|
|
if len(l.KV) > 0 { |
|
buf.AppendString("> ") |
|
kvfmt.Format(buf, l.KV...) |
|
} |
|
|
|
buf.AppendString("\n") |
|
|
|
_, err := o.Write(buf.Bytes()) |
|
|
|
BufPool.Put(buf) |
|
|
|
return err |
|
} |
|
|
|
func (o *outputStd) Close() error { |
|
return nil |
|
} |
|
|
|
func NewStderrOutput() Output { |
|
return &outputStd{ |
|
Writer: os.Stderr, |
|
} |
|
} |
|
|
|
func NewStdoutOutput() Output { |
|
return &outputStd{ |
|
Writer: os.Stdout, |
|
} |
|
} |
|
|
|
/* |
|
######################################################################################################## @(°_°)@ ####### |
|
*/
|
|
|