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 (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"gitea.suyono.dev/suyono/wingmate/daemon"
|
|
||||||
"github.com/rs/zerolog"
|
"github.com/rs/zerolog"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Level zerolog.Level
|
type Level zerolog.Level
|
||||||
|
|
||||||
|
type Payload zerolog.Event
|
||||||
|
|
||||||
type ProcessLogConfig interface {
|
type ProcessLogConfig interface {
|
||||||
Method() string
|
Method() string
|
||||||
FileName() string
|
FileName() string
|
||||||
@ -37,24 +38,44 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (l Level) Print(a ...any) {
|
func (l Level) Print(a ...any) {
|
||||||
var event *zerolog.Event
|
// var event *zerolog.Event
|
||||||
for _, i := range a {
|
// for _, i := range a {
|
||||||
if event == nil {
|
// 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))
|
event = logger.WithLevel(zerolog.Level(l))
|
||||||
}
|
for i, part := range a {
|
||||||
switch v := i.(type) {
|
if i%2 == 0 {
|
||||||
case daemon.ProcessLogEntry:
|
key = part.(string)
|
||||||
event = event.Str("type", v.Descriptor.InstanceType().String()).Str("origin", "child process").
|
} else {
|
||||||
Str("name", v.Descriptor.Name())
|
switch v := part.(type) {
|
||||||
if v.Descriptor.InstanceType() == daemon.Cron {
|
case string:
|
||||||
event = event.Str("instance_name", v.Descriptor.InstanceName())
|
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) {
|
func Print(a ...any) {
|
||||||
globalLevel.Print(a...)
|
globalLevel.Print(a...)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user