Skip to content

Commit

Permalink
Added logging levels.
Browse files Browse the repository at this point in the history
  • Loading branch information
BenDol committed Jul 30, 2014
1 parent 9ba2195 commit df6d3b4
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 18 deletions.
27 changes: 26 additions & 1 deletion candybot.otui
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,37 @@ MainWindow
margin-bottom: -5
@onClick: CandyBot.hide()

ComboBox
id: loggerType
!tooltip: tr('Log level determining what log messages will be shown. This will show messages')
anchors.left: parent.left
anchors.bottom: parent.bottom
margin-bottom: -10
margin-left: -7
options:
-Info
-Warning
-Error
-Debug
@onOptionChange: |
local option = self:getCurrentOption()
if option.text == "Info" then
BotLogger.logType = BotLogTypes.info
elseif option.text == "Warning" then
BotLogger.logType = BotLogTypes.warning
elseif option.text == "Error" then
BotLogger.logType = BotLogTypes.error
elseif option.text == Debug then
BotLogger.logType = BotLogTypes.debug
end

Label
id: versionInfo
!text: tr('')
anchors.left: parent.left
anchors.left: loggerType.right
anchors.bottom: parent.bottom
margin-bottom: -5
margin-left: 5
color: #ffffff44
text-auto-resize: true

Expand Down
44 changes: 32 additions & 12 deletions logger.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
BotLogger = {}

BotLogTypes = {
warning = 1,
error = 2,
debug = 3
info = 1,
warning = 2,
error = 3,
debug = 4
}
BotLogger.logType = BotLogTypes.info

local MAX_LINES = 35

Expand All @@ -22,6 +24,10 @@ function BotLogger.init()
logBuffer = logWindow:getChildById('logBuffer')
end

function BotLogger.info(msg)
BotLogger.print(BotLogTypes.info, msg)
end

function BotLogger.warning(msg)
BotLogger.print(BotLogTypes.warning, msg)
end
Expand All @@ -38,15 +44,29 @@ function BotLogger.print(type, msg)
local trace = debug.getinfo(debug.getinfo(3, "f").func)
local path = BotLogger.trimPath(trace.short_src:explode("/"))

if type == BotLogTypes.warning then
--g_logger.warning(msg)
BotLogger.createLabel(msg, "yellow")
elseif type == BotLogTypes.error then
--g_logger.error(msg)
BotLogger.createLabel(msg, "red")
elseif type == BotLogTypes.debug then
--g_logger.debug(msg)
BotLogger.createLabel(msg, "white")
if BotLogger.logType then

if type == BotLogTypes.info then
if BotLogger.logType >= BotLogTypes.info then
--g_logger.info(msg)
BotLogger.createLabel(msg, "white")
end
elseif type == BotLogTypes.warning then
if BotLogger.logType >= BotLogTypes.warning then
--g_logger.warning(msg)
BotLogger.createLabel(msg, "yellow")
end
elseif type == BotLogTypes.error then
if BotLogger.logType >= BotLogTypes.error then
--g_logger.error(msg)
BotLogger.createLabel(msg, "red")
end
elseif type == BotLogTypes.debug then
if BotLogger.logType >= BotLogTypes.debug then
--g_logger.debug(msg)
BotLogger.createLabel(msg, "green")
end
end
end
end

Expand Down
2 changes: 1 addition & 1 deletion modules/00-bot/events/disablebot.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ function Disable.Event(event)
botIcon:setTooltip("Disabled")

CandyBot.enable(false)
BotLogger.warning("Bot disabled.")
BotLogger.info("Bot disabled.")
end
4 changes: 2 additions & 2 deletions modules/00-bot/events/enablebot.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ function Enable.Event(event)
EventHandler.signal() -- signal events to start
ListenerHandler.signal() -- signal listeners to start

BotLogger.warning("Bot enabled.")
BotLogger.info("Bot enabled.")

if g_game.isOfficialTibia() then
BotLogger.warning("Note: Bags must be open for certain bot features.")
BotLogger.info("Note: Bags must be open for certain bot features.")
end
end
2 changes: 1 addition & 1 deletion modules/01-afk/afk.otui
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ Panel
BotOptionCheckBox
id: AutoReplaceWeapon
!text: tr('Auto Replace Weapons')
!tooltip: tr('Automatically "refill" used throwing weapons (container of replacing items must be open).')
!tooltip: tr('Automatically "refill" used throwing weapons\n(container of replacing items must be open).')
anchors.left: parent.left
anchors.top: prev.top
margin-top: 10
Expand Down
2 changes: 1 addition & 1 deletion modules/04-targets/targets.lua
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ function TargetsModule.bindHandlers()
TargetsModule.setCurrentSetting(selectedTarget:getSetting(1))
end
else
currentSetting = false
currentSetting = nil
TargetsModule.syncSetting()
end
end
Expand Down

0 comments on commit df6d3b4

Please sign in to comment.