Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions common/lib/logger.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,49 +14,54 @@ local logger = {
messageBuffer = RingBuffer(2048)
}

logger.TRACE = 0 -- Log something that is very detailed verbose debug logging
logger.DEBUG = 1 -- Log something that is only useful when debugging
logger.INFO = 2 -- Log something that is useful in most normal conditions
logger.WARN = 3 -- Log something that could be a problem
logger.ERROR = 4 -- Log something that definitely is a problem
---@enum LogLevel
logger.levels = {
TRACE = 0, -- Log something that is very detailed verbose debug logging
DEBUG = 1, -- Log something that is only useful when debugging
INFO = 2, -- Log something that is useful in most normal conditions
WARN = 3, -- Log something that could be a problem
ERROR = 4 -- Log something that definitely is a problem
}

local LOG_LEVEL = logger.DEBUG
---@type LogLevel
logger.logLevel = logger.levels.DEBUG

---@param level LogLevel use logger.levels. to access presets
function logger.setLogLevel(level)
LOG_LEVEL = level
logger.logLevel = level
end

-- See comments above about when you should use each logging level
function logger.trace(msg)
if LOG_LEVEL <= logger.TRACE then
if logger.logLevel <= logger.levels.TRACE then
direct_log("TRACE", msg);
end
end

-- See comments above about when you should use each logging level
function logger.debug(msg)
if LOG_LEVEL <= logger.DEBUG then
if logger.logLevel <= logger.levels.DEBUG then
direct_log("DEBUG", msg);
end
end

-- See comments above about when you should use each logging level
function logger.info(msg)
if LOG_LEVEL <= logger.INFO then
if logger.logLevel <= logger.levels.INFO then
direct_log(" INFO", msg);
end
end

-- See comments above about when you should use each logging level
function logger.warn(msg)
if LOG_LEVEL <= logger.WARN then
if logger.logLevel <= logger.levels.WARN then
direct_log(" WARN", msg);
end
end

-- See comments above about when you should use each logging level
function logger.error(msg)
if LOG_LEVEL <= logger.ERROR then
if logger.logLevel <= logger.levels.ERROR then
direct_log("ERROR", msg);
end
end
Expand Down
15 changes: 14 additions & 1 deletion serverLauncher.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
local logger = require("common.lib.logger")

if arg[1] == "debug" then
-- for debugging in visual studio code
pcall(function() require("lldebugger").start() end)
if os.getenv("LOCAL_LUA_DEBUGGER_VSCODE") == "1" then
-- VS Code / VS Codium
require("lldebugger").start()
elseif pcall(function() require("mobdebug") end) then
-- ZeroBrane
-- afaik there is no good way to detect whether the game was started with zerobrane other than trying the require and succeeding
require("mobdebug").start()
require('mobdebug').coro()
end
logger.setLogLevel(logger.levels.DEBUG)
else
logger.setLogLevel(logger.levels.INFO)
end

-- We must launch the server from the root directory so all the requires are the right path relatively.
Expand Down
4 changes: 2 additions & 2 deletions testLauncher.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ local logger = require("common.lib.logger")

-- Set log level based on debug argument
if arg[2] == "debug" then
logger.setLogLevel(logger.DEBUG)
logger.setLogLevel(logger.levels.DEBUG)
else
logger.setLogLevel(logger.INFO)
logger.setLogLevel(logger.levels.INFO)
end

require("client.src.globals")
Expand Down