improvement(debug): better logs
This commit is contained in:
parent
4d3687f627
commit
4054bbe443
5 changed files with 43 additions and 20 deletions
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
|
@ -7,6 +7,7 @@
|
||||||
"core",
|
"core",
|
||||||
"scenes",
|
"scenes",
|
||||||
"utils",
|
"utils",
|
||||||
"birb"
|
"birb",
|
||||||
|
"enum"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,9 +25,18 @@ local DebugSystem = Object:extend()
|
||||||
|
|
||||||
local lovebird = require "birb.libs.lovebird"
|
local lovebird = require "birb.libs.lovebird"
|
||||||
|
|
||||||
function DebugSystem:new(controller, active)
|
local Levels = enum {
|
||||||
|
"ERROR",
|
||||||
|
"WARNING",
|
||||||
|
"INFO",
|
||||||
|
"DEBUG"
|
||||||
|
}
|
||||||
|
|
||||||
|
function DebugSystem:new(controller)
|
||||||
self.controller = controller
|
self.controller = controller
|
||||||
self.active = active or false
|
|
||||||
|
self.debugLevel = self.controller.conf.debugLevel or Levels.INFO
|
||||||
|
self.active = (self.debugLevel == Levels.DEBUG)
|
||||||
if (self.active) then
|
if (self.active) then
|
||||||
lovebird.update()
|
lovebird.update()
|
||||||
end
|
end
|
||||||
|
@ -42,27 +51,39 @@ end
|
||||||
-- PRINT FUNCTIONS
|
-- PRINT FUNCTIONS
|
||||||
-- Print and log debug string
|
-- Print and log debug string
|
||||||
|
|
||||||
function DebugSystem:print(context, string)
|
function DebugSystem:debug(context, string)
|
||||||
if (self.active) then
|
self:log(Levels.DEBUG, context, string)
|
||||||
print(self:getLogLine("DEBUG", context, string))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function DebugSystem:print(context, string)
|
||||||
|
self:log(Levels.INFO, context, string)
|
||||||
end
|
end
|
||||||
|
|
||||||
function DebugSystem:warning(context, string)
|
function DebugSystem:warning(context, string)
|
||||||
if (self.active) then
|
self:log(Levels.WARNING, context, string)
|
||||||
print(self:getLogLine("WARNING", context, string))
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function DebugSystem:error(context, string)
|
function DebugSystem:error(context, string)
|
||||||
error(self:getLogLine("ERROR", context, string))
|
self:log(Levels.ERROR, context, string)
|
||||||
|
error(self:getMessage(": ", context, string))
|
||||||
end
|
end
|
||||||
|
|
||||||
function DebugSystem:getLogLine(type, string1, string2)
|
function DebugSystem:log(level, context, string)
|
||||||
|
if (self.debugLevel >= level) then
|
||||||
|
print(self:getLogLine(Levels[level], context, string))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function DebugSystem:getLogLine(type, context, string)
|
||||||
|
local head = self.controller:getIdentity(false) .. "|" .. os.date("%x-%X") .. "|" .. type .. "|"
|
||||||
|
return head .. self:getMessage("|", context, string)
|
||||||
|
end
|
||||||
|
|
||||||
|
function DebugSystem:getMessage(separator, string1, string2)
|
||||||
if (string2 == nil) then
|
if (string2 == nil) then
|
||||||
return "[" .. type .. "] " .. string1
|
return string1
|
||||||
else
|
else
|
||||||
return "[" .. type .. "] " .. string1 .. ": " .. string2
|
return string1 .. separator .. string2
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -38,10 +38,10 @@ local SceneManager = require(cwd .. "scenemanager")
|
||||||
-- INIT FUNCTIONS
|
-- INIT FUNCTIONS
|
||||||
-- Initialize and configure the core object
|
-- Initialize and configure the core object
|
||||||
|
|
||||||
function CoreSystem:new(isDebug)
|
function CoreSystem:new()
|
||||||
self:setDefaultConf()
|
self:setDefaultConf()
|
||||||
|
|
||||||
self.debug = DebugSystem(self, isDebug)
|
self.debug = DebugSystem(self)
|
||||||
self.options = Options(self)
|
self.options = Options(self)
|
||||||
self.input = Input(self)
|
self.input = Input(self)
|
||||||
self.screen = Screen(self)
|
self.screen = Screen(self)
|
||||||
|
|
|
@ -29,18 +29,19 @@ birb = {}
|
||||||
|
|
||||||
Object = require("birb.libs.classic")
|
Object = require("birb.libs.classic")
|
||||||
utils = require("birb.utils")
|
utils = require("birb.utils")
|
||||||
|
enum = require("birb.utils.enum")
|
||||||
|
|
||||||
birb.Core = require("birb.core")
|
birb.Core = require("birb.core")
|
||||||
|
|
||||||
function birb.start(gamemodule, isDebug)
|
function birb.start(gamemodule)
|
||||||
birb.startCore((isDebug == true))
|
birb.startCore()
|
||||||
if (gamemodule ~= nil) then
|
if (gamemodule ~= nil) then
|
||||||
birb.startGame(gamemodule)
|
birb.startGame(gamemodule)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function birb.startCore(isDebug)
|
function birb.startCore()
|
||||||
core = birb.Core(isDebug)
|
core = birb.Core()
|
||||||
end
|
end
|
||||||
|
|
||||||
function birb.startGame(gamemodule)
|
function birb.startGame(gamemodule)
|
||||||
|
|
|
@ -26,6 +26,6 @@ require "birb"
|
||||||
scenes = require "scenes"
|
scenes = require "scenes"
|
||||||
|
|
||||||
function love.load()
|
function love.load()
|
||||||
birb.start("game", false)
|
birb.start("game")
|
||||||
scenes.title()
|
scenes.title()
|
||||||
end
|
end
|
Loading…
Reference in a new issue