-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhandlers.py
More file actions
30 lines (21 loc) · 924 Bytes
/
Copy pathhandlers.py
File metadata and controls
30 lines (21 loc) · 924 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from __future__ import annotations
import copy
import logging.handlers
from typing import TYPE_CHECKING, override
if TYPE_CHECKING:
from logging import LogRecord
class CustomQueueHandler(logging.handlers.QueueHandler):
"""Prevents mutation of LogRecord objects before queuing."""
@override
def prepare(self, record: LogRecord) -> LogRecord:
"""Override to prevent log record mutation by the base class.
The base class mutates log entries before sending them to the queue. This method
creates a shallow copy of the record, calculates the message, and returns the copy.
Args:
record (LogRecord): The log record to be prepared.
Returns:
LogRecord: A shallow copy of the record with the message attribute set.
"""
record_copy = copy.copy(record)
record_copy.message = record.getMessage()
return record_copy