wip: log
This commit is contained in:
20
log/log.go
20
log/log.go
@@ -3,11 +3,24 @@ package log
|
||||
import (
|
||||
"gitea.suyono.dev/suyono/wingmate/daemon"
|
||||
"github.com/rs/zerolog"
|
||||
"io"
|
||||
"os"
|
||||
"sync"
|
||||
)
|
||||
|
||||
type Level zerolog.Level
|
||||
|
||||
type ProcessLogConfig interface {
|
||||
Method() string
|
||||
FileName() string
|
||||
}
|
||||
|
||||
type Writer struct {
|
||||
writer io.Writer
|
||||
mtx *sync.Mutex
|
||||
wg *sync.WaitGroup
|
||||
} //TODO: create a writer implementation using this struct, ensure sync and prevent abrupt truncation when stopping
|
||||
|
||||
const (
|
||||
Trace Level = Level(zerolog.TraceLevel)
|
||||
Debug Level = Level(zerolog.DebugLevel)
|
||||
@@ -29,8 +42,11 @@ func init() {
|
||||
}
|
||||
|
||||
func (l Level) Print(a ...any) {
|
||||
event := logger.WithLevel(zerolog.Level(l))
|
||||
var event *zerolog.Event
|
||||
for _, i := range a {
|
||||
if event == nil {
|
||||
event = logger.WithLevel(zerolog.Level(l))
|
||||
}
|
||||
switch v := i.(type) {
|
||||
case daemon.ProcessLogEntry:
|
||||
event = event.Str("type", v.Descriptor.InstanceType().String()).Str("origin", "child process").
|
||||
@@ -39,6 +55,8 @@ func (l Level) Print(a ...any) {
|
||||
event = event.Str("instance_name", v.Descriptor.InstanceName())
|
||||
}
|
||||
event.Str("entry", v.LogEntry).Send()
|
||||
event = nil
|
||||
//TODO: add logic to process cron or service specific log config
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user