logger
Lightweight logging utility with colored console output and file handlers.
BaseLogger ¶
Lightweight application logger with file and console handlers.
BaseLogger is a small wrapper around Python's standard logging that configures a file handler and a console handler (with colors). It is implemented as a simple singleton so multiple instantiations return the same configured logger instance.
Source code in src/mangetamain/utils/logger.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 | |
__new__ ¶
__new__(input_name=None)
Init or return the singleton logger instance.
Source code in src/mangetamain/utils/logger.py
57 58 59 60 61 62 | |
critical ¶
critical(msg)
Log a critical-level message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
msg
|
str
|
Message to log at CRITICAL level. |
required |
Source code in src/mangetamain/utils/logger.py
153 154 155 156 157 158 159 | |
debug ¶
debug(msg)
Log a debug-level message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
msg
|
str
|
Message to log at DEBUG level. |
required |
Source code in src/mangetamain/utils/logger.py
128 129 130 131 132 133 134 | |
error ¶
error(msg)
Log an error message and mark that an error occurred.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
msg
|
str
|
Message to log at ERROR level. |
required |
Source code in src/mangetamain/utils/logger.py
144 145 146 147 148 149 150 151 | |
get_log_path ¶
get_log_path()
Return the current log file path.
Returns:
| Name | Type | Description |
|---|---|---|
Path |
Path
|
Path to the active log file. |
Source code in src/mangetamain/utils/logger.py
161 162 163 164 165 166 167 | |
has_errors ¶
has_errors()
Return whether an error has been logged during runtime.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if any error was logged, otherwise False. |
Source code in src/mangetamain/utils/logger.py
169 170 171 172 173 174 175 | |
info ¶
info(msg)
Log an informational message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
msg
|
str
|
Message to log at INFO level. |
required |
Source code in src/mangetamain/utils/logger.py
120 121 122 123 124 125 126 | |
warning ¶
warning(msg)
Log a warning-level message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
msg
|
str
|
Message to log at WARNING level. |
required |
Source code in src/mangetamain/utils/logger.py
136 137 138 139 140 141 142 | |
ColoredFormatter ¶
Bases: Formatter
A logging formatter that adds ANSI color codes to console output.
This formatter applies simple ANSI color codes to the formatted message according to the record level name (DEBUG, INFO, WARNING, ERROR, CRITICAL). It improves readability when logs are viewed in a terminal that supports ANSI escapes.
Source code in src/mangetamain/utils/logger.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | |
format ¶
format(record)
Format the record and wrap it in color escape sequences.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
record
|
LogRecord
|
The logging.Record to format. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The formatted log string with ANSI color codes applied. |
Source code in src/mangetamain/utils/logger.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | |
RotLogger ¶
Bases: BaseLogger
Logger using a rotating file handler to bound log file size.
RotLogger uses :class:logging.handlers.RotatingFileHandler to
keep logs from growing indefinitely by rotating them when they
exceed a configured size.
Source code in src/mangetamain/utils/logger.py
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 | |
TimeLogger ¶
Bases: BaseLogger
Logger that writes timestamped log files into a per-run folder.
This variant of :class:BaseLogger creates a new timestamped file
for each run inside logs/<input_name>/ which is useful when
keeping separate logs per execution is desired.
Source code in src/mangetamain/utils/logger.py
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 | |
get_logger ¶
get_logger()
Return the module-level configured logger instance.
Returns:
| Name | Type | Description |
|---|---|---|
RotLogger |
RotLogger
|
The shared logger instance used by the application. |
Source code in src/mangetamain/utils/logger.py
245 246 247 248 249 250 251 | |