-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLogger.lua
127 lines (112 loc) · 3 KB
/
Logger.lua
1
--[[ * Copyright (c) 2011-2012 by Adam Hellberg. * * This file is part of Command. * * Command is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Command is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Command. If not, see <http://www.gnu.org/licenses/>.--]]-- Upvalueslocal tostring = tostringlocal C = Command--- Table containing all Logger methods.-- This is referenced "Logger" in Logger.lua.-- @name Command.Logger-- @class table-- @field Level Table containing all logger levels.-- @field Settings Table containing all settings specific to Logger.--C.Logger = { Level = { Debug = 0, Normal = 1, Warning = 2, Error = 3 }, Settings = { Debug = false, Format = "%s%s: %s", }}local Logger = C.Loggerlocal L = C.LocaleManager-------------------------- MAIN LOGGER MODULE ----------------------------- Print a log message at the specified level.-- @param msg Message to pring.-- @param level One of the levels defined in Logger.Level.--function Logger:Print(msg, level) local prefix if level == self.Level.Debug then if not self.Settings.Debug then return end prefix = L("LOGGER_PREFIX_DEBUG") elseif level == self.Level.Normal then prefix = L("LOGGER_PREFIX_NORMAL") elseif level == self.Level.Warning then prefix = L("LOGGER_PREFIX_WARNING") elseif level == self.Level.Error then prefix = L("LOGGER_PREFIX_ERROR") else error(L("LOGGER_ERR_UNDEFINED"):format(tostring(level))) return end DEFAULT_CHAT_FRAME:AddMessage(self.Settings.Format:format(L("LOGGER_PREFIX_MAIN"):format(C.Name), prefix, msg))end--- Print a debug message.-- @param msg Message to print.--function Logger:Debug(msg) self:Print(msg, self.Level.Debug)end--- Print a normal message-- @param msg Message to print.--function Logger:Normal(msg) self:Print(msg, self.Level.Normal)end--- Print a warning message.-- @param msg Message to pring.--function Logger:Warning(msg) self:Print(msg, self.Level.Warning)end--- Print an error message.-- @param msg Message to print.--function Logger:Error(msg) self:Print(msg, self.Level.Error)end--- Control the debug state.-- Setting debugging to enabled will enable debug messages to be printed.-- @param enabled Boolean indicating enabled or disabled state.--function Logger:SetDebug(enabled) self.Settings.Debug = enabledend--- Enable debugging.--function Logger:EnableDebug() self:SetDebug(true)end--- Disable debugging.--function Logger:DisableDebug() self:SetDebug(false)end--- Toggle debugging.--function Logger:ToggleDebug() self:SetDebug(not self.Settings.Debug)end