Logging Events
If you want to add custom logging to existing plugins, or custom plugins then follow the instructions below.
Logging can make it easier to debug code, keep track of bot events in the server, etc.
You can optionally disable logging in your config.ini file.
Logging Features
- There are various logging levels (INFO, WARNING, CRITICAL) in which each level indicates the severity of the event. In most cases the INFO level is used to log general bot events.
- The logging system also supports specifying the origin of the log event. The logging origin definitions are
as follows:
L_GENERAL
= "General"L_USER_PRIV
= "UserPrivileges"L_DATABASE
= "Database"L_COMMAND
= "Command"L_STARTUP
= "StartUp"L_SHUTDOWN
= "ShutDown"L_ALIASES
= "Aliases"L_LOGGING
= "Logging"L_DEPENDENCIES
= "Dependencies"
Logging Steps
- Open the python script you wish to add logging to.
- Add this line to the top of the file:
'from JJMumbleBot.lib.utils.logging_utils import log'
Importing the logging_utils file will allow you to use the logger that is used for the entire bot. - To log an event you can use:
'log(log_level, log_message, origin=log_origin)'
Example Usage:
log(INFO, "I logged an info event!", origin=L_GENERAL)
output: [JJMumbleBot(3.0.4).Aliases]: I logged a critical event!
output: [JJMumbleBot(3.0.4).General]: I logged an info event! log(WARNING, "I logged a warning event!", origin=L_LOGGING)
output: [JJMumbleBot(3.0.4).Logging]: I logged a warning event! log(CRITICAL, "I logged a critical issue!", origin=L_ALIASES)
By default, logs are time rotated every day at midnight.
The bot will store a maximum of 20 logs (20 days worth) before recycling the oldest logs.
Example Saved Log: