|
49 | 49 | _LOGGING_JSON_SORT_KEYS = 1 |
50 | 50 | _LOGGING_JSON_INDENT = 1 |
51 | 51 |
|
| 52 | +# https://github.com/awslabs/aws-lambda-powertools-python/blob/develop/aws_lambda_powertools/logging/formatter.py |
| 53 | +RESERVED_LOG_ATTRS = ( |
| 54 | + "name", |
| 55 | + "msg", |
| 56 | + "args", |
| 57 | + "level", |
| 58 | + "levelname", |
| 59 | + "levelno", |
| 60 | + "pathname", |
| 61 | + "filename", |
| 62 | + "module", |
| 63 | + "exc_info", |
| 64 | + "exc_text", |
| 65 | + "stack_info", |
| 66 | + "lineno", |
| 67 | + "funcName", |
| 68 | + "created", |
| 69 | + "msecs", |
| 70 | + "relativeCreated", |
| 71 | + "thread", |
| 72 | + "threadName", |
| 73 | + "processName", |
| 74 | + "process", |
| 75 | + "asctime", |
| 76 | + "location", |
| 77 | + "timestamp", |
| 78 | +) |
| 79 | + |
52 | 80 |
|
53 | 81 | # private |
54 | 82 |
|
@@ -387,3 +415,46 @@ def format(self, record): |
387 | 415 |
|
388 | 416 | def __getattr__(self, attr): |
389 | 417 | return getattr(self.base_formatter, attr) |
| 418 | + |
| 419 | + |
| 420 | +class SuppressFilter(logging.Filter): |
| 421 | + """Suppress Filter. |
| 422 | + """ |
| 423 | + |
| 424 | + # noinspection PyMissingConstructor |
| 425 | + def __init__(self, logger): |
| 426 | + self.logger = logger |
| 427 | + |
| 428 | + def filter(self, record): # noqa: A003 |
| 429 | + """Suppress Log Records from registered logger. |
| 430 | +
|
| 431 | + It rejects log records from registered logger |
| 432 | + e.g. a child logger otherwise it honours log |
| 433 | + propagation from any log record created by loggers |
| 434 | + who don't have a handler. |
| 435 | +
|
| 436 | + Args: |
| 437 | + record (logging.LogRecord): Log Record. |
| 438 | +
|
| 439 | + Returns: |
| 440 | + bool: True if record should be filtered, otherwise False. |
| 441 | + """ |
| 442 | + logger = record.name |
| 443 | + return self.logger not in logger |
| 444 | + |
| 445 | + |
| 446 | +class SyslogBOMFormatter(logging.Formatter): |
| 447 | + """Syslog BOM Formatter |
| 448 | + """ |
| 449 | + |
| 450 | + def format(self, record): |
| 451 | + """Format Log Record. |
| 452 | +
|
| 453 | + Args: |
| 454 | + record (logging.LogRecord): Log Record. |
| 455 | +
|
| 456 | + Returns: |
| 457 | + str: Formatted Log Record. |
| 458 | + """ |
| 459 | + result = super(SyslogBOMFormatter, self).format(record) |
| 460 | + return "ufeff{0}".format(result) |
0 commit comments