wip: log
This commit is contained in:
parent
1f25e5249c
commit
8a480acde7
51
log/log.go
51
log/log.go
@ -3,12 +3,13 @@ package log
|
||||
import (
|
||||
"os"
|
||||
|
||||
"gitea.suyono.dev/suyono/wingmate/daemon"
|
||||
"github.com/rs/zerolog"
|
||||
)
|
||||
|
||||
type Level zerolog.Level
|
||||
|
||||
type Payload zerolog.Event
|
||||
|
||||
type ProcessLogConfig interface {
|
||||
Method() string
|
||||
FileName() string
|
||||
@ -37,23 +38,43 @@ func init() {
|
||||
}
|
||||
|
||||
func (l Level) Print(a ...any) {
|
||||
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").
|
||||
Str("name", v.Descriptor.Name())
|
||||
if v.Descriptor.InstanceType() == daemon.Cron {
|
||||
event = event.Str("instance_name", v.Descriptor.InstanceName())
|
||||
// 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").
|
||||
// Str("name", v.Descriptor.Name())
|
||||
// if v.Descriptor.InstanceType() == daemon.Cron {
|
||||
// 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
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
func (l Level) Fields(a ...any) *Payload {
|
||||
var (
|
||||
event *zerolog.Event
|
||||
key string
|
||||
)
|
||||
|
||||
event = logger.WithLevel(zerolog.Level(l))
|
||||
for i, part := range a {
|
||||
if i%2 == 0 {
|
||||
key = part.(string)
|
||||
} else {
|
||||
switch v := part.(type) {
|
||||
case string:
|
||||
event = event.Str(key, v)
|
||||
}
|
||||
event.Str("entry", v.LogEntry).Send()
|
||||
event = nil
|
||||
//TODO: add logic to process cron or service specific log config
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func Print(a ...any) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user