Logger¶
Internal API
These classes are for internal use only.
Users should interact with Client and other public API classes instead.
Important
If quiet = dev_mode = True
: quiet OVERRIDES dev_mode.
DEBUG will NOT print!
Logger
¶
A utility class for logging messages, supporting log levels, color-coded console output, optional file logging, and redaction of sensitive information.
Initializes logger. Opens log file 'bot.log' for writing.
Parameters:
-
dev_mode
(bool
, default:False
) –toggle debug messages. Defaults to False.
-
quiet
(bool
, default:False
) –(bool, optional): supress low-priority logs (INFO, DEBUG, WARN). Defaults to False.
DEBUG = '\x1b[36m'
class-attribute
instance-attribute
¶
Debug color: CYCAN
INFO = '\x1b[32m'
class-attribute
instance-attribute
¶
Info color: GREEN
WARNING = '\x1b[33m'
class-attribute
instance-attribute
¶
Warning color: YELLOW
ERROR = '\x1b[31m'
class-attribute
instance-attribute
¶
Error color: RED
CRITICAL = '\x1b[41m'
class-attribute
instance-attribute
¶
Critical color: RED HIGHLIGHT
TIME = '\x1b[90m'
class-attribute
instance-attribute
¶
Timestamp color: GRAY
RESET = '\x1b[0m'
class-attribute
instance-attribute
¶
Reset color: DEFAULT
fp = open('bot.log', 'w', encoding='utf-8')
instance-attribute
¶
Log file for writing.
dev_mode = dev_mode
instance-attribute
¶
If debug logs should be printed.
quiet = quiet
instance-attribute
¶
If only high-level logs should be printed.
now
¶
Returns current timestamp
Returns:
-
str
–timestamp formatted in YYYY-MM-DD HH:MM:SS
_log
¶
Internal helper that writes formatted log to both file and console.
Parameters:
-
level
(str
) –DEBUG, INFO, WARN, CRITICAL, ERROR
-
color
(str
) –color specified by Logger properties
-
message
(str
) –descriptive message to log
log_debug
¶
Logs a debug-level message.
Parameters:
-
message
(str
) –descriptive message to log
log_info
¶
Logs a info-level message.
Parameters:
-
message
(str
) –descriptive message to log
log_warn
¶
Logs a warn-level message.
Parameters:
-
message
(str
) –descriptive message to log
log_error
¶
Logs a error-level message.
Parameters:
-
message
(str
) –descriptive message to log
log_critical
¶
Logs a critical-level message.
Parameters:
-
message
(str
) –descriptive message to log
log_high_priority
¶
Always log this, regardless of quiet/dev_mode.
Parameters:
-
message
(str
) –descriptive message to log
redact
¶
Recusively redact sensitive fields (token, password, authorization, api_key) from data.
Parameters:
-
data
(_type_
) –JSON to sanitize
-
replacement
(str
, default:'*** REDACTED ***'
) –what sensitive data is replaced with. Defaults to ' REDACTED '.
Returns:
-
dict
–sanitized JSON
close
¶
Closes the log file.