Quantcast
Download
(7 Kb)
Download
Updated: 06/01/19 08:23 AM
Pictures
File Info
Compatibility:
Elsweyr (5.0.5)
Updated:06/01/19 08:23 AM
Created:02/26/19 10:22 AM
Monthly downloads:7,432
Total downloads:103,082
Favorites:180
MD5:
LibDebugLogger  Popular! (More than 5000 hits)
Version: 1.1.0
by: sirinsidiator [More]
This library provides facilities to log debug output in the background without running the risk of it showing in the chat output. It can also be very helpful in debugging issues out in the wild, since it will store the output into its saved variable file. It will automatically log information about the current client. During startup the library will default to log all log levels and stack traces, until the saved variables become available.

The log output can be inspected with the help of the DebugLogViewer add-on.

Features

Client Information
The library will automatically log the following information about a character on login:
  • account name - in case you play with multiple accounts and that is somehow causing issues (e.g. with the saved variables)
  • character name - in case the problem occurs due to switching characters or due to some special characters in the name
  • login time - in case a problem occurs a fixed time after logging in on the character
  • client version - hope that doesn't need an explanation
  • mega server - in case of server specific issues
  • service type - steam or non-steam in case that makes a difference
  • UI type - keyboard or console UI is quite an important detail
  • ESO+ - changes how some APIs react
  • language - in case it is some localization problem
  • out of date checkbox state - good to know when someone has an issue with some add-on not loading
  • add-on count - how many are active and how many are installed
  • add-on load events - this gives information about the load order of your add-ons, the loaded add-on version and which subdirectory of the add-on folder it was loaded from

In addition it will also log Lua errors, add-on output done via the in-game debug functions d(), df() and CHAT_SYSTEM:AddMessage(), alert messages in the error category and loading screens.

Stack Traces
Usually only Lua errors contain a stack trace, but the library can be configured to log the stack trace for any message. Due to the fact that saved settings are not available until after an add-on has fully loaded, the library will default to log everything during login and switch to the configured settings afterwards.

Logger Class
Authors can create a logger object which can be used to log messages of different severity (debug/info/warning/error). Those messages will be marked with the tag passed to the logger on creation and can be easily filtered that way.

A logger can create any number of sub-instances which will use the original tag with another part appended. This can be useful for big add-ons with many components, or when some very verbose logging should be disabled for a release version without having to remove all calls to the logger.

Quick Start
Add LibDebugLogger as a dependency to your add-on manifest:
Code:
## DependsOn: LibDebugLogger
Afterwards you can create a logger instance and start logging messages like so:
Lua Code:
  1. local logger = LibDebugLogger("MyAddon")
  2. logger:Debug("A debug message")
  3. logger:Info("An", "info", "message") -- multiple arguments are passed through tostring and concatenated with a space in between
  4. logger:Warn("A %s message: %d", "formatted", 123) -- if the first parameter contains formatting strings, the logger will pass all arguments through string.format instead
  5. local subLogger = logger:Create("verbose") -- this will create a separate logger with a combined tag "MyAddon/verbose".
  6. subLogger:SetEnabled(false) -- turn the new logger off
  7. subLogger:Error("An error message") -- this won't show up

Settings
The /debuglogger slash command can be used to configure what should get logged or show the current settings when no value is passed to a setting.

/debuglogger stack <on/off> - when turned on, the library will log the stack trace for the logger call. Can be very useful to figure out where a log is coming from.

/debuglogger level <d(ebug)/i(nfo)/w(arning)/e(rror)> - determines the minimum severity for logs to be stored

/debuglogger clear - will delete all stored logs

LibDebugLogger will automatically remove old logs after one day, or when the total amount surpasses 11k entries.

API Reference

LibDebugLogger.DEFAULT_SETTINGS
This constant contains the default settings for the library. The contained values should not be changed.

LibDebugLogger.TAG_INGAME
This constant contains the tag that is used to log messages that are generated by in-game methods (Lua Errors, chat debug output, alerts).

Log Levels
This values of the available log levels are stored in the following four constants:
  • LibDebugLogger.LOG_LEVEL_DEBUG = "D"
  • LibDebugLogger.LOG_LEVEL_INFO = "I"
  • LibDebugLogger.LOG_LEVEL_WARNING = "W"
  • LibDebugLogger.LOG_LEVEL_ERROR = "E"
The log levels are also stored in the LibDebugLogger.LOG_LEVELS array in order of their severity.
There are also two mappings LibDebugLogger.LOG_LEVEL_TO_STRING and LibDebugLogger.STR_TO_LOG_LEVEL which can be used to convert the level values into untranslated lowercase strings and back.

Log Entry Indices
A log entry is a numerically indexed table with the following values:
  1. raw timestamp in milliseconds
  2. human readable time
  3. occurrence count
  4. log level
  5. tag
  6. message
  7. stack trace (optional)
To use the values one can either use the unpack function and assign them to variables, or directly access them with the following index constants:
  • LibDebugLogger.ENTRY_TIME_INDEX
  • LibDebugLogger.ENTRY_FORMATTED_TIME_INDEX
  • LibDebugLogger.ENTRY_OCCURENCES_INDEX
  • LibDebugLogger.ENTRY_LEVEL_INDEX
  • LibDebugLogger.ENTRY_TAG_INDEX
  • LibDebugLogger.ENTRY_MESSAGE_INDEX
  • LibDebugLogger.ENTRY_STACK_INDEX

Create
This function will return an instance of a logger. Anything logged via that instance will automatically contain the tag for easy identification.
Code:
local logger = LibDebugLogger.Create("MyAddon")
or
Code:
local logger = LibDebugLogger("MyAddon")
Logger:Create
Convenience method to create a new instance of the logger with a combined tag. Can be used to separate logs from different files. Anything logged via that instance will automatically contain the parent tag and the child tag separated by a slash (e.g. MyAddon/SomeFile).

Code:
local subLogger = logger:Create("SomeFile")
Logger:SetEnabled
Setter to turn this logger off, so it no longer adds anything to the log when one of its log methods is called.

Code:
logger:SetEnabled(false)
Logger:Debug
Method to log messages with the debug log level. If the first argument is a formatting string, the method will call string.format, otherwise each argument will get passed through tostring and concatenated with a space.

Code:
logger:Debug("My formatted message: %s", "some text")
logger:Debug("My", "combined", "message")
Logger:Info
Method to log messages with the info log level. See Debug method for details.

Logger:Warn
Method to log messages with the warning log level. See Debug method for details.

Logger:Error
Method to log messages with the error log level. See Debug method for details.

GetSessionStartTime
Function to get the time when the client was started in milliseconds.
Code:
local sessionStartTime = LibDebugLogger:GetSessionStartTime()
GetUiLoadStartTime
Function to get the approximate time when the UI has started loading in milliseconds. There is currently no way to get the real time, so instead this is just the time when LibDebugLogger.lua is executed first, which can be happen several seconds after the actual UI load start. Since the purpose of this function is to provide a way to discern log messages that have been created in the current UI load, this is fine.
Code:
local uiLoadStartTime = LibDebugLogger:GetUiLoadStartTime()
IsTraceLoggingEnabled
Returns true if the library is set to capture stack traces for all messages.
Code:
local isTraceLoggingEnabled = LibDebugLogger:IsTraceLoggingEnabled()
SetTraceLoggingEnabled
Sets stack traces capturing for all messages enabled or disabled.
Code:
LibDebugLogger:SetTraceLoggingEnabled(enabled)
GetMinLogLevel
Returns the minimum log level.
Code:
local minLogLevel = LibDebugLogger:GetMinLogLevel()
SetMinLogLevel
Sets the minimum log level. Has to be one of the values in the LOG_LEVELS constant.
Code:
LibDebugLogger:SetMinLogLevel(level)
GetLog
Returns the current log table.
Code:
LibDebugLogger:GetLog()
ClearLog
Clears the log by creating a new table.
Code:
LibDebugLogger:ClearLog()
SetBlockChatOutputEnabled
Function to block showing chat debug messages created via d(), df() or CHAT_SYSTEM:AddMessage() in the regular chat. Can be used by other add-ons that display the log content, to avoid having the messages show up twice on screen. Should be called as early as possible.
Code:
LibDebugLogger:SetBlockChatOutputEnabled(enabled)
IsBlockChatOutputEnabled
Returns true if chat debug messages are blocked from showing in chat.
Code:
local isBlocked = LibDebugLogger:IsBlockChatOutputEnabled()
CombineSplitStringIfNeeded
This method rebuilds the input string in case it has been split up to circumvent the saved variables string length limit.
Code:
input = LibDebugLogger.CombineSplitStringIfNeeded(input)
RegisterCallback
The library fires callbacks whenever the log is modified. Callbacks should be as lightweight as possible. If you plan to use expensive calls, defer the execution with zo_callLater!
Code:
LibDebugLogger:RegisterCallback(callbackName, callback)
CALLBACK_LOG_CLEARED
This callback is fired whenever the log is cleared completely.
Code:
LibDebugLogger:RegisterCallback(LibDebugLogger.CALLBACK_LOG_CLEARED, function()
    -- do something
end)
CALLBACK_LOG_PRUNED
This callback is fired whenever the log is trimmed back to 10k entries due to the length exceeding the maximum allowed entry count of 11k entries.
Pruning will create a new log table and the startIndex passed to the callback is the first index in the old log table that will be kept in the new log.
Code:
LibDebugLogger:RegisterCallback(LibDebugLogger.CALLBACK_LOG_PRUNED, function(startIndex)
    -- do something
end)
CALLBACK_LOG_ADDED
This callback is fired whenever a log entry is added. The entry parameter is the data as stored in the log and wasDuplicate is true when the entry had the same message, level and stack trace as the previous one and only the time and occurrence count was adjusted.
Code:
LibDebugLogger:RegisterCallback(LibDebugLogger.CALLBACK_LOG_CLEARED, function(entry, wasDuplicate)
    -- do something
end)
v1.1.0
- added new APIs (see description for full details)
* settings functions
* getters for session and ui start time
* function to rebuild split log strings
* various constants, enums and variables
* callbacks for log modifications
- improved slash command settings menu
- reuse provided stack trace from Lua errors when possible
- update last logging time on identical log messages
- added chat debug output logging
- added ingame error alert logging
- added loading screens logging
- added IsLibrary flag

v1.0.2
- prune log during session before it grows too big to load on next login
- store identical messages following after one another only once and start counting afterwards
- some minor code and performance improvements

v1.0.1
- added a safeguard to ensure logging an error won't ever create more errors
- added more debug information to startup log (e.g. platform, ui, addon paths, ...)
- fixed LibDebugLogger("MyAddon") passing the wrong argument as tag
Archived Files (3)
File Name
Version
Size
Uploader
Date
1.0.2
5kB
sirinsidiator
03/16/19 04:39 AM
1.0.1
4kB
sirinsidiator
03/04/19 12:10 PM
1.0.0
4kB
sirinsidiator
02/26/19 10:22 AM


Post A Reply Comment Options
Unread 08/25/19, 10:17 AM  
IceHeart
AddOn Author - Click to view AddOns

Forum posts: 0
File comments: 3
Uploads: 1
req: Unique call with severity parameter

Sir,

Small feature request at:
https://www.esoui.com/portal.php?id=...featureid=1750
(making sure you see it )

Thanks for the great work!
Report comment to moderator  
Reply With Quote
Unread 06/11/19, 04:46 AM  
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view AddOns

Forum posts: 1288
File comments: 802
Uploads: 34
This error doesn't tell me much. Could you please upload the LibDebugLogger.lua from your saved variables somewhere and send me a link? Otherwise I won't be able to fix this.
__________________
Like what I do? Support me on Patreon!
>siri.exe MyAddon
Does your addon work? [y/n] n
There is a typo in there.
Report comment to moderator  
Reply With Quote
Unread 06/11/19, 02:14 AM  
zelenin
AddOn Author - Click to view AddOns

Forum posts: 2
File comments: 52
Uploads: 2
user:/AddOns/LibDebugLogger/LibDebugLogger.lua:108: attempt to index a nil value
stack traceback:
user:/AddOns/LibDebugLogger/LibDebugLogger.lua:108: in function 'FormatTime'
user:/AddOns/LibDebugLogger/LibDebugLogger.lua:401: in function '(main chunk)'
Report comment to moderator  
Reply With Quote
Unread 05/20/19, 09:41 AM  
Rhyono
AddOn Author - Click to view AddOns

Forum posts: 554
File comments: 1083
Uploads: 19
Reminder: check the box to show it is up to date.
Report comment to moderator  
Reply With Quote
Unread 03/16/19, 04:40 AM  
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view AddOns

Forum posts: 1288
File comments: 802
Uploads: 34
Thanks to everyone who sent in their files I was able to identify the problem. Turned out that it is caused by other addons that throw a large number of errors and fill up the LibDebugLogger saved variables until the game can no longer load it. I have updated LibDebugLogger so it keeps its log at a manageable size during the session instead of only removing surplus entries at login.
The two addons I have identified so far are BugCatcher and LUI Extended. I have contacted the author of LUI Extended and the error there should be fixed soon. BugCatcher seems to be abandoned and you should probably disable it, as it is throwing multiple errors per frame, which can have a severe impact on the game performance.
__________________
Like what I do? Support me on Patreon!
>siri.exe MyAddon
Does your addon work? [y/n] n
There is a typo in there.
Report comment to moderator  
Reply With Quote
Unread 03/11/19, 03:45 PM  
StytchFingal

Forum posts: 0
File comments: 18
Uploads: 0
Deleting the lua file from Saved Variables also worked for me. Thank you!

Before the delete, the DebugLogger was crashing me back to the login screen from any attempt at character load.
Report comment to moderator  
Reply With Quote
Unread 03/11/19, 02:52 PM  
Seminolegirl1992

Forum posts: 0
File comments: 5
Uploads: 0
Re: Re: Not working for me

Originally Posted by sirinsidiator
Have you tried to remove the LibDebugLogger.lua from your Saved Variables folder? Does it work then?
Otherwise I need more information. More specifically the operating system you are using and any errors or other unusual entries in the interface.log file in live/Logs.
Omg it worked!!!!!!! You are amazing. Thanks a million times for responding.
Report comment to moderator  
Reply With Quote
Unread 03/11/19, 01:25 PM  
mausibox01

Forum posts: 0
File comments: 1
Uploads: 0
hey there,
I had the same issue as written below but to delete the debuglogger.lua from saved variables works fine for me. thanks for that. appriciate your fast response to that question.
Report comment to moderator  
Reply With Quote
Unread 03/11/19, 01:10 PM  
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view AddOns

Forum posts: 1288
File comments: 802
Uploads: 34
Re: Not working for me

Have you tried to remove the LibDebugLogger.lua from your Saved Variables folder? Does it work then?
Otherwise I need more information. More specifically the operating system you are using and any errors or other unusual entries in the interface.log file in live/Logs.
__________________
Like what I do? Support me on Patreon!
>siri.exe MyAddon
Does your addon work? [y/n] n
There is a typo in there.
Report comment to moderator  
Reply With Quote
Unread 03/11/19, 01:05 PM  
Seminolegirl1992

Forum posts: 0
File comments: 5
Uploads: 0
Not working for me

Hiya. I posted on Awesome Guild Store's comment section a few days back...I finally isolated my issue to this library precisely, but I am unsure how to fix it. Every other lib works fine, as does AGS, but when I select this lib to load, it crashes back to log-in screen. Any ideas on how to fix this? I know most people have this add-on and its libraries working fine, so it's probably only on my end. Thanks!!
Report comment to moderator  
Reply With Quote
Unread 03/02/19, 02:26 PM  
Architecture
 
Architecture's Avatar
AddOn Author - Click to view AddOns

Forum posts: 7
File comments: 73
Uploads: 8
nice job on this! Love the log stack trace feature too.
Report comment to moderator  
Reply With Quote
Post A Reply



Category Jump:

Support AddOn Development!

You have just downloaded by the author . If you like this AddOn why not consider supporting the author? This author has set up a donation account. Donations ensure that authors can continue to develop useful tools for everyone.