mirror of
https://github.com/akyaiy/GoSally-mvp.git
synced 2026-01-03 17:52:24 +00:00
update lua logging
This commit is contained in:
@@ -82,29 +82,33 @@ func (h *HandlerV1) handleLUA(sid string, r *http.Request, req *rpc.RPCRequest,
|
|||||||
for name, logFunc := range logFuncs {
|
for name, logFunc := range logFuncs {
|
||||||
fun := logFunc
|
fun := logFunc
|
||||||
lL.SetField(logMod, name, lL.NewFunction(func(lL *lua.LState) int {
|
lL.SetField(logMod, name, lL.NewFunction(func(lL *lua.LState) int {
|
||||||
msg := lL.ToString(1)
|
msg := lL.Get(1)
|
||||||
fun(fmt.Sprintf("the script says: %s", msg), slog.String("script", path))
|
converted := ConvertLuaTypesToGolang(msg)
|
||||||
|
fun(fmt.Sprintf("the script says: %s", converted), slog.String("script", path))
|
||||||
return 0
|
return 0
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
lL.SetField(logMod, "event", lL.NewFunction(func(lL *lua.LState) int {
|
for _, fn := range []struct {
|
||||||
msg := lL.ToString(1)
|
field string
|
||||||
h.x.Log.Printf("%s: %s", path, msg)
|
pfunc func(string, ...any)
|
||||||
return 0
|
color func() string
|
||||||
}))
|
}{
|
||||||
|
{"event", h.x.Log.Printf, nil},
|
||||||
lL.SetField(logMod, "event_error", lL.NewFunction(func(lL *lua.LState) int {
|
{"event_error", h.x.Log.Printf, colors.PrintError},
|
||||||
msg := lL.ToString(1)
|
{"event_warn", h.x.Log.Printf, colors.PrintWarn},
|
||||||
h.x.Log.Printf("%s: %s: %s", colors.PrintError(), path, msg)
|
} {
|
||||||
return 0
|
lL.SetField(logMod, fn.field, lL.NewFunction(func(lL *lua.LState) int {
|
||||||
}))
|
msg := lL.Get(1)
|
||||||
|
converted := ConvertLuaTypesToGolang(msg)
|
||||||
lL.SetField(logMod, "event_warn", lL.NewFunction(func(lL *lua.LState) int {
|
if fn.color != nil {
|
||||||
msg := lL.ToString(1)
|
h.x.Log.Printf("%s: %s: %s", fn.color(), path, converted)
|
||||||
h.x.Log.Printf("%s: %s: %s", colors.PrintWarn(), path, msg)
|
} else {
|
||||||
return 0
|
h.x.Log.Printf("%s: %s", path, converted)
|
||||||
}))
|
}
|
||||||
|
return 0
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
lL.Push(logMod)
|
lL.Push(logMod)
|
||||||
lL.SetField(logMod, "__gosally_internal", lua.LString(fmt.Sprint(seed)))
|
lL.SetField(logMod, "__gosally_internal", lua.LString(fmt.Sprint(seed)))
|
||||||
|
|||||||
Reference in New Issue
Block a user