wg_utilities.loggers
Useful constants and functions for use in logging in other projects.
FlushableQueueListener
Bases: QueueListener
A QueueListener that can be flushed and stopped.
Source code in wg_utilities/loggers/item_warehouse/flushable_queue_listener.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
|
flush_and_stop(timeout=300)
Wait for the queue to empty and stop.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
timeout |
float
|
the maximum time to wait for the queue to empty |
300
|
Source code in wg_utilities/loggers/item_warehouse/flushable_queue_listener.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
|
ListHandler
Bases: Handler
Custom handler to allow retrieval of log records after the fact.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
records_list |
list
|
allows the user to pass in a pre-defined list to add records to |
None
|
Source code in wg_utilities/loggers/list_handler.py
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 44 45 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 |
|
critical_records: list[LogRecord]
property
Critical level records.
Returns:
Name | Type | Description |
---|---|---|
list |
list[LogRecord]
|
a list of log records with the level CRITICAL |
debug_records: list[LogRecord]
property
Debug level records.
Returns:
Name | Type | Description |
---|---|---|
list |
list[LogRecord]
|
a list of log records with the level DEBUG |
error_records: list[LogRecord]
property
Error level records.
Returns:
Name | Type | Description |
---|---|---|
list |
list[LogRecord]
|
a list of log records with the level ERROR |
info_records: list[LogRecord]
property
Info level records.
Returns:
Name | Type | Description |
---|---|---|
list |
list[LogRecord]
|
a list of log records with the level INFO |
records: list[LogRecord]
property
All records.
Returns:
Name | Type | Description |
---|---|---|
list |
list[LogRecord]
|
a list of log records with the level CRITICAL |
warning_records: list[LogRecord]
property
Warning level records.
Returns:
Name | Type | Description |
---|---|---|
list |
list[LogRecord]
|
a list of log records with the level WARNING |
emit(record)
Add log record to the internal record store.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
record |
LogRecord
|
the new log record being "emitted" |
required |
Source code in wg_utilities/loggers/list_handler.py
40 41 42 43 44 45 46 47 48 49 50 51 |
|
expire_records()
Remove records older than self.ttl
, and call self.on_expiry
on them.
Source code in wg_utilities/loggers/list_handler.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
|
WarehouseHandler
Bases: BaseWarehouseHandler
Custom handler to allow logging directly into an Item Warehouse.
https://github.com/worgarside/addon-item-warehouse-api https://github.com/worgarside/addon-item-warehouse-website
The primary key of the log warehouse is a combination of
- log_hash (message content)
- logger (name of the logger)
- log_host (hostname of the machine the log was generated on)
This means that the same log message from the same host will only be stored once.
Source code in wg_utilities/loggers/item_warehouse/warehouse_handler.py
33 34 35 36 37 38 39 40 41 42 43 44 45 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 |
|
__init__(*, level='INFO', warehouse_host=None, warehouse_port=None, initialize_warehouse=False)
Initialize the handler and Log Warehouse.
Source code in wg_utilities/loggers/item_warehouse/warehouse_handler.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
|
emit(record)
Add log record to the internal record store.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
record |
LogRecord
|
the new log record being "emitted" |
required |
Source code in wg_utilities/loggers/item_warehouse/warehouse_handler.py
66 67 68 69 70 71 72 73 74 75 |
|
initialize_warehouse()
Create a new warehouse or validate an existing one.
Source code in wg_utilities/loggers/item_warehouse/warehouse_handler.py
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 |
|
post_with_backoff(log_payload)
Post a JSON response to the warehouse, with backoff applied.
Source code in wg_utilities/loggers/item_warehouse/warehouse_handler.py
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 |
|
add_file_handler(logger, *, logfile_path, level=DEBUG, create_directory=True)
Add a FileHandler to an existing logger.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
logger |
Logger
|
the logger to add a file handler to |
required |
logfile_path |
Path
|
the path to the logging file |
required |
level |
int
|
the logging level to be used for the FileHandler |
DEBUG
|
create_directory |
bool
|
whether to force-create the directory/ies the file is contained within |
True
|
Returns:
Name | Type | Description |
---|---|---|
Logger |
Logger
|
the logger instance, returned for use in one-liners:
|
Source code in wg_utilities/loggers/file_handler.py
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 |
|
add_list_handler(logger, *, log_list=None, level=DEBUG, log_ttl=86400, on_expiry=None)
Add a ListHandler to an existing logger.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
logger |
Logger
|
the logger to add a file handler to |
required |
log_list |
list
|
the list for the handler to write logs to |
None
|
level |
int
|
the logging level to be used for the ListHandler |
DEBUG
|
log_ttl |
int
|
number of seconds to retain a log for |
86400
|
on_expiry |
Callable
|
function to call with expired logs |
None
|
Source code in wg_utilities/loggers/list_handler.py
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
|
add_stream_handler(logger, *, formatter=FORMATTER, level=DEBUG)
Add a FileHandler to an existing logger.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
logger |
Logger
|
the logger to add a file handler to |
required |
formatter |
Formatter
|
the formatter to use in the stream logs |
FORMATTER
|
level |
int
|
the logging level to be used for the FileHandler |
DEBUG
|
Returns:
Name | Type | Description |
---|---|---|
Logger |
Logger
|
the logger instance, returned for use in one-liners:
|
Source code in wg_utilities/loggers/stream_handler.py
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 |
|
add_warehouse_handler(logger, *, level=DEBUG, warehouse_host=None, warehouse_port=None, initialize_warehouse=False, disable_queue=False)
Add a WarehouseHandler to an existing logger.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
logger |
Logger
|
the logger to add a file handler to |
required |
level |
int
|
the logging level to be used for the WarehouseHandler |
DEBUG
|
warehouse_host |
str
|
the hostname of the Item Warehouse |
None
|
warehouse_port |
int
|
the port of the Item Warehouse |
None
|
initialize_warehouse |
bool
|
whether to initialize the Warehouse |
False
|
disable_queue |
bool
|
whether to disable the queue for the WarehouseHandler |
False
|
Returns:
Name | Type | Description |
---|---|---|
WarehouseHandler |
WarehouseHandler
|
the WarehouseHandler that was added to the logger |
Source code in wg_utilities/loggers/item_warehouse/warehouse_handler.py
167 168 169 170 171 172 173 174 175 176 177 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 206 207 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 |
|
create_file_handler(logfile_path, level=DEBUG, *, create_directory=True)
Create a file handler for use in other loggers.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
logfile_path |
str
|
the path to the logging file |
required |
level |
int
|
the logging level to be used for the FileHandler |
DEBUG
|
create_directory |
bool
|
whether to force-create the directory/ies the file is contained within |
True
|
Returns:
Name | Type | Description |
---|---|---|
FileHandler |
FileHandler
|
a log handler with a file as the output |
Source code in wg_utilities/loggers/file_handler.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
|
get_streaming_logger(name, *, formatter=FORMATTER, level=DEBUG)
Get a logger with a StreamHandler attached.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
the name of the logger to create |
required |
formatter |
Formatter
|
the formatter to use in the stream logs |
FORMATTER
|
level |
int
|
the logging level to be used for the FileHandler |
DEBUG
|
Returns:
Name | Type | Description |
---|---|---|
Logger |
Logger
|
the logger instance, returned for use in one-liners:
|
Source code in wg_utilities/loggers/stream_handler.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
|
file_handler
Helper functions for creating and adding FileHandlers to loggers.
add_file_handler(logger, *, logfile_path, level=DEBUG, create_directory=True)
Add a FileHandler to an existing logger.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
logger |
Logger
|
the logger to add a file handler to |
required |
logfile_path |
Path
|
the path to the logging file |
required |
level |
int
|
the logging level to be used for the FileHandler |
DEBUG
|
create_directory |
bool
|
whether to force-create the directory/ies the file is contained within |
True
|
Returns:
Name | Type | Description |
---|---|---|
Logger |
Logger
|
the logger instance, returned for use in one-liners:
|
Source code in wg_utilities/loggers/file_handler.py
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 |
|
create_file_handler(logfile_path, level=DEBUG, *, create_directory=True)
Create a file handler for use in other loggers.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
logfile_path |
str
|
the path to the logging file |
required |
level |
int
|
the logging level to be used for the FileHandler |
DEBUG
|
create_directory |
bool
|
whether to force-create the directory/ies the file is contained within |
True
|
Returns:
Name | Type | Description |
---|---|---|
FileHandler |
FileHandler
|
a log handler with a file as the output |
Source code in wg_utilities/loggers/file_handler.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
|
item_warehouse
Logging utilities specific to the Item Warehouse project.
https://github.com/worgarside/addon-item-warehouse-api https://github.com/worgarside/addon-item-warehouse-website
WarehouseHandler
Bases: BaseWarehouseHandler
Custom handler to allow logging directly into an Item Warehouse.
https://github.com/worgarside/addon-item-warehouse-api https://github.com/worgarside/addon-item-warehouse-website
The primary key of the log warehouse is a combination of
- log_hash (message content)
- logger (name of the logger)
- log_host (hostname of the machine the log was generated on)
This means that the same log message from the same host will only be stored once.
Source code in wg_utilities/loggers/item_warehouse/warehouse_handler.py
33 34 35 36 37 38 39 40 41 42 43 44 45 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 |
|
__init__(*, level='INFO', warehouse_host=None, warehouse_port=None, initialize_warehouse=False)
Initialize the handler and Log Warehouse.
Source code in wg_utilities/loggers/item_warehouse/warehouse_handler.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
|
emit(record)
Add log record to the internal record store.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
record |
LogRecord
|
the new log record being "emitted" |
required |
Source code in wg_utilities/loggers/item_warehouse/warehouse_handler.py
66 67 68 69 70 71 72 73 74 75 |
|
initialize_warehouse()
Create a new warehouse or validate an existing one.
Source code in wg_utilities/loggers/item_warehouse/warehouse_handler.py
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 |
|
post_with_backoff(log_payload)
Post a JSON response to the warehouse, with backoff applied.
Source code in wg_utilities/loggers/item_warehouse/warehouse_handler.py
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 |
|
add_warehouse_handler(logger, *, level=DEBUG, warehouse_host=None, warehouse_port=None, initialize_warehouse=False, disable_queue=False)
Add a WarehouseHandler to an existing logger.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
logger |
Logger
|
the logger to add a file handler to |
required |
level |
int
|
the logging level to be used for the WarehouseHandler |
DEBUG
|
warehouse_host |
str
|
the hostname of the Item Warehouse |
None
|
warehouse_port |
int
|
the port of the Item Warehouse |
None
|
initialize_warehouse |
bool
|
whether to initialize the Warehouse |
False
|
disable_queue |
bool
|
whether to disable the queue for the WarehouseHandler |
False
|
Returns:
Name | Type | Description |
---|---|---|
WarehouseHandler |
WarehouseHandler
|
the WarehouseHandler that was added to the logger |
Source code in wg_utilities/loggers/item_warehouse/warehouse_handler.py
167 168 169 170 171 172 173 174 175 176 177 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 206 207 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 |
|
base_handler
Custom handler to allow logging directly into an Item Warehouse.
BaseWarehouseHandler
Bases: Handler
, JsonApiClient[WarehouseLog | WarehouseLogPage]
Custom handler to allow logging directly into an Item Warehouse.
https://github.com/worgarside/addon-item-warehouse-api https://github.com/worgarside/addon-item-warehouse-website
The primary key of the log warehouse is a combination of
- log_hash (message content)
- logger (name of the logger)
- log_host (hostname of the machine the log was generated on)
This means that the same log message from the same host will only be stored once.
Source code in wg_utilities/loggers/item_warehouse/base_handler.py
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 176 177 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 206 207 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 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 |
|
__eq__(other)
Compare two WarehouseHandlers for equality.
Source code in wg_utilities/loggers/item_warehouse/base_handler.py
279 280 281 282 283 284 285 |
|
__init__(*, level='INFO', warehouse_host=None, warehouse_port=None)
Initialize the handler.
Source code in wg_utilities/loggers/item_warehouse/base_handler.py
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
|
get_base_url(host, port)
staticmethod
Get the base URL for the Item Warehouse.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
host |
str
|
the hostname of the Item Warehouse |
required |
port |
int
|
the port of the Item Warehouse |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
the base URL for the Item Warehouse |
Source code in wg_utilities/loggers/item_warehouse/base_handler.py
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 |
|
get_log_hash(record)
staticmethod
Get a hash of the log message.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
record |
LogRecord
|
the log record to hash |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
the hexdigest of the hash |
Source code in wg_utilities/loggers/item_warehouse/base_handler.py
230 231 232 233 234 235 236 237 238 239 240 |
|
get_log_payload(record)
staticmethod
Get a log payload from a log record.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
record |
LogRecord
|
the log record to convert |
required |
Returns:
Name | Type | Description |
---|---|---|
LogPayload |
LogPayload
|
the converted log payload |
Source code in wg_utilities/loggers/item_warehouse/base_handler.py
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 |
|
LogPayload
Bases: TypedDict
Type for a log payload.
Source code in wg_utilities/loggers/item_warehouse/base_handler.py
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
|
WarehouseLog
Bases: TypedDict
Type for a log record.
Source code in wg_utilities/loggers/item_warehouse/base_handler.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
|
WarehouseLogPage
Bases: TypedDict
Type for a page of log records.
Source code in wg_utilities/loggers/item_warehouse/base_handler.py
21 22 23 24 25 26 27 |
|
WarehouseSchema
Bases: TypedDict
Type for a Warehouse schema.
Source code in wg_utilities/loggers/item_warehouse/base_handler.py
63 64 65 66 67 68 69 |
|
flushable_queue_listener
Simple subclass of logging.handlers.QueueListener that can be flushed and stopped.
FlushableQueueListener
Bases: QueueListener
A QueueListener that can be flushed and stopped.
Source code in wg_utilities/loggers/item_warehouse/flushable_queue_listener.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
|
flush_and_stop(timeout=300)
Wait for the queue to empty and stop.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
timeout |
float
|
the maximum time to wait for the queue to empty |
300
|
Source code in wg_utilities/loggers/item_warehouse/flushable_queue_listener.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
|
warehouse_handler
Custom handler to allow logging directly into an Item Warehouse.
WarehouseHandler
Bases: BaseWarehouseHandler
Custom handler to allow logging directly into an Item Warehouse.
https://github.com/worgarside/addon-item-warehouse-api https://github.com/worgarside/addon-item-warehouse-website
The primary key of the log warehouse is a combination of
- log_hash (message content)
- logger (name of the logger)
- log_host (hostname of the machine the log was generated on)
This means that the same log message from the same host will only be stored once.
Source code in wg_utilities/loggers/item_warehouse/warehouse_handler.py
33 34 35 36 37 38 39 40 41 42 43 44 45 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 |
|
__init__(*, level='INFO', warehouse_host=None, warehouse_port=None, initialize_warehouse=False)
Initialize the handler and Log Warehouse.
Source code in wg_utilities/loggers/item_warehouse/warehouse_handler.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
|
emit(record)
Add log record to the internal record store.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
record |
LogRecord
|
the new log record being "emitted" |
required |
Source code in wg_utilities/loggers/item_warehouse/warehouse_handler.py
66 67 68 69 70 71 72 73 74 75 |
|
initialize_warehouse()
Create a new warehouse or validate an existing one.
Source code in wg_utilities/loggers/item_warehouse/warehouse_handler.py
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 |
|
post_with_backoff(log_payload)
Post a JSON response to the warehouse, with backoff applied.
Source code in wg_utilities/loggers/item_warehouse/warehouse_handler.py
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 |
|
add_warehouse_handler(logger, *, level=DEBUG, warehouse_host=None, warehouse_port=None, initialize_warehouse=False, disable_queue=False)
Add a WarehouseHandler to an existing logger.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
logger |
Logger
|
the logger to add a file handler to |
required |
level |
int
|
the logging level to be used for the WarehouseHandler |
DEBUG
|
warehouse_host |
str
|
the hostname of the Item Warehouse |
None
|
warehouse_port |
int
|
the port of the Item Warehouse |
None
|
initialize_warehouse |
bool
|
whether to initialize the Warehouse |
False
|
disable_queue |
bool
|
whether to disable the queue for the WarehouseHandler |
False
|
Returns:
Name | Type | Description |
---|---|---|
WarehouseHandler |
WarehouseHandler
|
the WarehouseHandler that was added to the logger |
Source code in wg_utilities/loggers/item_warehouse/warehouse_handler.py
167 168 169 170 171 172 173 174 175 176 177 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 206 207 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 |
|
list_handler
Helper class to allow retrieval of log records after the fact.
ListHandler
Bases: Handler
Custom handler to allow retrieval of log records after the fact.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
records_list |
list
|
allows the user to pass in a pre-defined list to add records to |
None
|
Source code in wg_utilities/loggers/list_handler.py
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 44 45 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 |
|
critical_records: list[LogRecord]
property
Critical level records.
Returns:
Name | Type | Description |
---|---|---|
list |
list[LogRecord]
|
a list of log records with the level CRITICAL |
debug_records: list[LogRecord]
property
Debug level records.
Returns:
Name | Type | Description |
---|---|---|
list |
list[LogRecord]
|
a list of log records with the level DEBUG |
error_records: list[LogRecord]
property
Error level records.
Returns:
Name | Type | Description |
---|---|---|
list |
list[LogRecord]
|
a list of log records with the level ERROR |
info_records: list[LogRecord]
property
Info level records.
Returns:
Name | Type | Description |
---|---|---|
list |
list[LogRecord]
|
a list of log records with the level INFO |
records: list[LogRecord]
property
All records.
Returns:
Name | Type | Description |
---|---|---|
list |
list[LogRecord]
|
a list of log records with the level CRITICAL |
warning_records: list[LogRecord]
property
Warning level records.
Returns:
Name | Type | Description |
---|---|---|
list |
list[LogRecord]
|
a list of log records with the level WARNING |
emit(record)
Add log record to the internal record store.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
record |
LogRecord
|
the new log record being "emitted" |
required |
Source code in wg_utilities/loggers/list_handler.py
40 41 42 43 44 45 46 47 48 49 50 51 |
|
expire_records()
Remove records older than self.ttl
, and call self.on_expiry
on them.
Source code in wg_utilities/loggers/list_handler.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
|
add_list_handler(logger, *, log_list=None, level=DEBUG, log_ttl=86400, on_expiry=None)
Add a ListHandler to an existing logger.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
logger |
Logger
|
the logger to add a file handler to |
required |
log_list |
list
|
the list for the handler to write logs to |
None
|
level |
int
|
the logging level to be used for the ListHandler |
DEBUG
|
log_ttl |
int
|
number of seconds to retain a log for |
86400
|
on_expiry |
Callable
|
function to call with expired logs |
None
|
Source code in wg_utilities/loggers/list_handler.py
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
|
stream_handler
Helper function to add a StreamHandler to a logger.
add_stream_handler(logger, *, formatter=FORMATTER, level=DEBUG)
Add a FileHandler to an existing logger.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
logger |
Logger
|
the logger to add a file handler to |
required |
formatter |
Formatter
|
the formatter to use in the stream logs |
FORMATTER
|
level |
int
|
the logging level to be used for the FileHandler |
DEBUG
|
Returns:
Name | Type | Description |
---|---|---|
Logger |
Logger
|
the logger instance, returned for use in one-liners:
|
Source code in wg_utilities/loggers/stream_handler.py
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 |
|
get_streaming_logger(name, *, formatter=FORMATTER, level=DEBUG)
Get a logger with a StreamHandler attached.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
the name of the logger to create |
required |
formatter |
Formatter
|
the formatter to use in the stream logs |
FORMATTER
|
level |
int
|
the logging level to be used for the FileHandler |
DEBUG
|
Returns:
Name | Type | Description |
---|---|---|
Logger |
Logger
|
the logger instance, returned for use in one-liners:
|
Source code in wg_utilities/loggers/stream_handler.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
|