log: Add structured logging (#1171)

* basic implementation

* log: deprecate duplicate function, add tests and refine calls.

* linter: fixes

* linter: update struct

* linter and new type

* log tests: update to not lint issue

* linter: stop complaining please

* glorious: nits

* log: rm comment code

* glorious: nits

* glorious: nits

* glorious: nits

* glorious: nits missed

---------

Co-authored-by: Ryan O'Hara-Reid <ryan.oharareid@thrasher.io>
This commit is contained in:
Ryan O'Hara-Reid
2023-05-10 17:52:53 +10:00
committed by GitHub
parent 6e1cbfc31e
commit db8735ec99
44 changed files with 679 additions and 476 deletions

View File

@@ -26,7 +26,7 @@ import (
// NewVM attempts to create a new Virtual Machine firstly from pool
func (g *GctScriptManager) NewVM() *VM {
if !g.IsRunning() {
log.Error(log.GCTScriptMgr, Error{
log.Errorln(log.GCTScriptMgr, Error{
Action: "NewVM",
Cause: ErrScriptingDisabled,
})
@@ -34,7 +34,7 @@ func (g *GctScriptManager) NewVM() *VM {
}
newUUID, err := uuid.NewV4()
if err != nil {
log.Error(log.GCTScriptMgr, Error{Action: "New: UUID", Cause: err})
log.Errorln(log.GCTScriptMgr, Error{Action: "New: UUID", Cause: err})
return nil
}
@@ -44,7 +44,7 @@ func (g *GctScriptManager) NewVM() *VM {
s, ok := pool.Get().(*tengo.Script)
if !ok {
log.Error(log.GCTScriptMgr, Error{
log.Errorln(log.GCTScriptMgr, Error{
Action: "NewVM",
Cause: errors.New("unable to type assert tengo script"),
})
@@ -144,30 +144,30 @@ func (vm *VM) CompileAndRun() {
}
err := vm.Compile()
if err != nil {
log.Error(log.GCTScriptMgr, err)
log.Errorln(log.GCTScriptMgr, err)
err = vm.unregister()
if err != nil {
log.Error(log.GCTScriptMgr, err)
log.Errorln(log.GCTScriptMgr, err)
}
return
}
err = vm.RunCtx()
if err != nil {
log.Error(log.GCTScriptMgr, err)
log.Errorln(log.GCTScriptMgr, err)
err = vm.unregister()
if err != nil {
log.Error(log.GCTScriptMgr, err)
log.Errorln(log.GCTScriptMgr, err)
}
return
}
if vm.Compiled.Get("timer").String() != "" {
vm.T, err = time.ParseDuration(vm.Compiled.Get("timer").String())
if err != nil {
log.Error(log.GCTScriptMgr, err)
log.Errorln(log.GCTScriptMgr, err)
err = vm.Shutdown()
if err != nil {
log.Error(log.GCTScriptMgr, err)
log.Errorln(log.GCTScriptMgr, err)
}
return
}
@@ -177,12 +177,12 @@ func (vm *VM) CompileAndRun() {
}
if vm.T < 0 {
log.Error(log.GCTScriptMgr, "Repeat timer cannot be under 1 nano second")
log.Errorln(log.GCTScriptMgr, "Repeat timer cannot be under 1 nano second")
}
}
err = vm.Shutdown()
if err != nil {
log.Error(log.GCTScriptMgr, err)
log.Errorln(log.GCTScriptMgr, err)
}
}

View File

@@ -18,7 +18,7 @@ func (vm *VM) runner() {
vm.NextRun = time.Now().Add(vm.T)
err := vm.RunCtx()
if err != nil {
log.Error(log.GCTScriptMgr, err)
log.Errorln(log.GCTScriptMgr, err)
return
}
case <-vm.S: