|
@@ -40,13 +40,19 @@ func (g *Gateway) injectStandardLibs(vm *otto.Otto, scriptFile string, scriptSco
|
|
|
|
|
|
|
|
// Override otto's built-in console.log (which maps to fmt.Println) so that
|
|
// Override otto's built-in console.log (which maps to fmt.Println) so that
|
|
|
// script output goes through the structured logger and carries the execID.
|
|
// script output goes through the structured logger and carries the execID.
|
|
|
|
|
+ // Use the system-wide logger (with file output) when available; fall back to
|
|
|
|
|
+ // agiLogger (stdout only) if the Gateway was created without one.
|
|
|
|
|
+ scriptLogger := agiLogger
|
|
|
|
|
+ if g.Option.Logger != nil {
|
|
|
|
|
+ scriptLogger = g.Option.Logger
|
|
|
|
|
+ }
|
|
|
vm.Set("_agi_console_log", func(call otto.FunctionCall) otto.Value {
|
|
vm.Set("_agi_console_log", func(call otto.FunctionCall) otto.Value {
|
|
|
parts := make([]string, 0, len(call.ArgumentList))
|
|
parts := make([]string, 0, len(call.ArgumentList))
|
|
|
for _, arg := range call.ArgumentList {
|
|
for _, arg := range call.ArgumentList {
|
|
|
str, _ := arg.ToString()
|
|
str, _ := arg.ToString()
|
|
|
parts = append(parts, str)
|
|
parts = append(parts, str)
|
|
|
}
|
|
}
|
|
|
- agiLogger.PrintAndLog("AGI", "["+execID+"] "+strings.Join(parts, " "), nil)
|
|
|
|
|
|
|
+ scriptLogger.PrintAndLog("AGI", "["+execID+"] "+strings.Join(parts, " "), nil)
|
|
|
return otto.UndefinedValue()
|
|
return otto.UndefinedValue()
|
|
|
})
|
|
})
|
|
|
vm.Run(`var console = { log: _agi_console_log, warn: _agi_console_log, error: _agi_console_log, info: _agi_console_log };`) //nolint:errcheck
|
|
vm.Run(`var console = { log: _agi_console_log, warn: _agi_console_log, error: _agi_console_log, info: _agi_console_log };`) //nolint:errcheck
|