wip: log
This commit is contained in:
parent
badd2e3543
commit
5621312be1
2
go.mod
2
go.mod
@ -3,6 +3,7 @@ module gitea.suyono.dev/suyono/wingmate
|
||||
go 1.20
|
||||
|
||||
require (
|
||||
github.com/rs/zerolog v1.30.0
|
||||
github.com/spf13/cobra v1.7.0
|
||||
github.com/spf13/viper v1.16.0
|
||||
github.com/stretchr/testify v1.8.4
|
||||
@ -20,7 +21,6 @@ require (
|
||||
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
||||
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
github.com/rs/zerolog v1.30.0 // indirect
|
||||
github.com/spf13/afero v1.9.5 // indirect
|
||||
github.com/spf13/cast v1.5.1 // indirect
|
||||
github.com/spf13/jwalterweatherman v1.1.0 // indirect
|
||||
|
||||
2
go.sum
2
go.sum
@ -326,8 +326,6 @@ golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBc
|
||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM=
|
||||
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o=
|
||||
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user