Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
f4a963760a | |||
d236811cb9 | |||
da93770334 |
@@ -28,6 +28,8 @@ const (
|
|||||||
LevelDebug
|
LevelDebug
|
||||||
// LevelTrace is for very detailed tracing information
|
// LevelTrace is for very detailed tracing information
|
||||||
LevelTrace
|
LevelTrace
|
||||||
|
// LevelLua is specifically for output from Lua scripts
|
||||||
|
LevelLua
|
||||||
)
|
)
|
||||||
|
|
||||||
var levelNames = map[LogLevel]string{
|
var levelNames = map[LogLevel]string{
|
||||||
@@ -36,6 +38,7 @@ var levelNames = map[LogLevel]string{
|
|||||||
LevelInfo: "INFO",
|
LevelInfo: "INFO",
|
||||||
LevelDebug: "DEBUG",
|
LevelDebug: "DEBUG",
|
||||||
LevelTrace: "TRACE",
|
LevelTrace: "TRACE",
|
||||||
|
LevelLua: "LUA",
|
||||||
}
|
}
|
||||||
|
|
||||||
var levelColors = map[LogLevel]string{
|
var levelColors = map[LogLevel]string{
|
||||||
@@ -44,6 +47,7 @@ var levelColors = map[LogLevel]string{
|
|||||||
LevelInfo: "\033[1;32m", // Bold Green
|
LevelInfo: "\033[1;32m", // Bold Green
|
||||||
LevelDebug: "\033[1;36m", // Bold Cyan
|
LevelDebug: "\033[1;36m", // Bold Cyan
|
||||||
LevelTrace: "\033[1;35m", // Bold Magenta
|
LevelTrace: "\033[1;35m", // Bold Magenta
|
||||||
|
LevelLua: "\033[1;34m", // Bold Blue
|
||||||
}
|
}
|
||||||
|
|
||||||
// ResetColor is the ANSI code to reset text color
|
// ResetColor is the ANSI code to reset text color
|
||||||
@@ -84,6 +88,8 @@ func ParseLevel(levelStr string) LogLevel {
|
|||||||
return LevelDebug
|
return LevelDebug
|
||||||
case "TRACE":
|
case "TRACE":
|
||||||
return LevelTrace
|
return LevelTrace
|
||||||
|
case "LUA":
|
||||||
|
return LevelLua
|
||||||
default:
|
default:
|
||||||
return defaultLogLevel
|
return defaultLogLevel
|
||||||
}
|
}
|
||||||
@@ -307,7 +313,8 @@ func (l *Logger) formatMessage(level LogLevel, format string, args ...interface{
|
|||||||
|
|
||||||
// log logs a message at the specified level
|
// log logs a message at the specified level
|
||||||
func (l *Logger) log(level LogLevel, format string, args ...interface{}) {
|
func (l *Logger) log(level LogLevel, format string, args ...interface{}) {
|
||||||
if level > l.currentLevel {
|
// Always show LUA level logs regardless of the current log level
|
||||||
|
if level != LevelLua && level > l.currentLevel {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -343,6 +350,11 @@ func (l *Logger) Trace(format string, args ...interface{}) {
|
|||||||
l.log(LevelTrace, format, args...)
|
l.log(LevelTrace, format, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Lua logs a Lua message
|
||||||
|
func (l *Logger) Lua(format string, args ...interface{}) {
|
||||||
|
l.log(LevelLua, format, args...)
|
||||||
|
}
|
||||||
|
|
||||||
// Global log functions that use DefaultLogger
|
// Global log functions that use DefaultLogger
|
||||||
|
|
||||||
// Error logs an error message using the default logger
|
// Error logs an error message using the default logger
|
||||||
@@ -385,6 +397,14 @@ func Trace(format string, args ...interface{}) {
|
|||||||
DefaultLogger.Trace(format, args...)
|
DefaultLogger.Trace(format, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Lua logs a Lua message using the default logger
|
||||||
|
func Lua(format string, args ...interface{}) {
|
||||||
|
if DefaultLogger == nil {
|
||||||
|
Init(defaultLogLevel)
|
||||||
|
}
|
||||||
|
DefaultLogger.Lua(format, args...)
|
||||||
|
}
|
||||||
|
|
||||||
// LogPanic logs a panic error and its stack trace
|
// LogPanic logs a panic error and its stack trace
|
||||||
func LogPanic(r interface{}) {
|
func LogPanic(r interface{}) {
|
||||||
if DefaultLogger == nil {
|
if DefaultLogger == nil {
|
||||||
|
@@ -314,6 +314,38 @@ function upper(s) return string.upper(s) end
|
|||||||
function lower(s) return string.lower(s) end
|
function lower(s) return string.lower(s) end
|
||||||
function format(s, ...) return string.format(s, ...) end
|
function format(s, ...) return string.format(s, ...) end
|
||||||
|
|
||||||
|
-- String split helper
|
||||||
|
function strsplit(inputstr, sep)
|
||||||
|
if sep == nil then
|
||||||
|
sep = "%s"
|
||||||
|
end
|
||||||
|
local t = {}
|
||||||
|
for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
|
||||||
|
table.insert(t, str)
|
||||||
|
end
|
||||||
|
return t
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param table table
|
||||||
|
---@param depth number?
|
||||||
|
function DumpTable(table, depth)
|
||||||
|
if depth == nil then
|
||||||
|
depth = 0
|
||||||
|
end
|
||||||
|
if (depth > 200) then
|
||||||
|
print("Error: Depth > 200 in dumpTable()")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
for k, v in pairs(table) do
|
||||||
|
if (type(v) == "table") then
|
||||||
|
print(string.rep(" ", depth) .. k .. ":")
|
||||||
|
DumpTable(v, depth + 1)
|
||||||
|
else
|
||||||
|
print(string.rep(" ", depth) .. k .. ": ", v)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-- String to number conversion helper
|
-- String to number conversion helper
|
||||||
function num(str)
|
function num(str)
|
||||||
return tonumber(str) or 0
|
return tonumber(str) or 0
|
||||||
@@ -412,12 +444,21 @@ func BuildLuaScript(luaExpr string) string {
|
|||||||
|
|
||||||
func printToGo(L *lua.LState) int {
|
func printToGo(L *lua.LState) int {
|
||||||
top := L.GetTop()
|
top := L.GetTop()
|
||||||
|
|
||||||
args := make([]interface{}, top)
|
args := make([]interface{}, top)
|
||||||
for i := 1; i <= top; i++ {
|
for i := 1; i <= top; i++ {
|
||||||
args[i-1] = L.Get(i)
|
args[i-1] = L.Get(i)
|
||||||
}
|
}
|
||||||
message := fmt.Sprint(args...)
|
|
||||||
logger.Info("[Lua] %s", message)
|
// Format the message with proper spacing between arguments
|
||||||
|
var parts []string
|
||||||
|
for _, arg := range args {
|
||||||
|
parts = append(parts, fmt.Sprintf("%v", arg))
|
||||||
|
}
|
||||||
|
message := strings.Join(parts, " ")
|
||||||
|
|
||||||
|
// Use the LUA log level with a script tag
|
||||||
|
logger.Lua("%s", message)
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user