Configure the application logger Args: loglevel (str): The level of logging for the application. log_mode (str): What kind of logging output to apply... text: Text logging is intended for users / developers. json: Json logging is intended for parsing with
(loglevel, log_mode)
| 8 | from pythonjsonlogger import jsonlogger |
| 9 | |
| 10 | def configure_logging(loglevel, log_mode): |
| 11 | """Configure the application logger |
| 12 | |
| 13 | Args: |
| 14 | loglevel (str): The level of logging for the application. |
| 15 | log_mode (str): What kind of logging output to apply... |
| 16 | text: Text logging is intended for users / developers. |
| 17 | json: Json logging is intended for parsing with a log aggregation system. |
| 18 | """ |
| 19 | |
| 20 | if not loglevel: |
| 21 | loglevel = logging.INFO |
| 22 | |
| 23 | if log_mode == 'json': |
| 24 | log_formatter = jsonlogger.JsonFormatter() |
| 25 | elif log_mode == 'text': |
| 26 | log_formatter = logging.Formatter('%(message)s') |
| 27 | elif log_mode == 'standard': |
| 28 | log_formatter = logging.Formatter( |
| 29 | '%(asctime)s - %(name)s - %(levelname)s - %(message)s' |
| 30 | ) |
| 31 | else: |
| 32 | log_formatter = logging.Formatter( |
| 33 | '%(asctime)s - %(name)s - %(levelname)s - %(message)s' |
| 34 | ) |
| 35 | |
| 36 | handler = logging.StreamHandler(sys.stdout) |
| 37 | handler.setFormatter(log_formatter) |
| 38 | root_logger = logging.getLogger() |
| 39 | root_logger.addHandler(handler) |
| 40 | root_logger.setLevel(loglevel) |
| 41 | |
| 42 | structlog.configure( |
| 43 | processors=[ |
| 44 | structlog.stdlib.filter_by_level, |
| 45 | structlog.stdlib.add_logger_name, |
| 46 | structlog.stdlib.add_log_level, |
| 47 | structlog.stdlib.PositionalArgumentsFormatter(), |
| 48 | structlog.processors.StackInfoRenderer(), |
| 49 | structlog.processors.format_exc_info, |
| 50 | structlog.processors.UnicodeDecoder(), |
| 51 | structlog.stdlib.render_to_log_kwargs, |
| 52 | ], |
| 53 | context_class=dict, |
| 54 | logger_factory=structlog.stdlib.LoggerFactory(), |
| 55 | wrapper_class=structlog.stdlib.BoundLogger, |
| 56 | cache_logger_on_first_use=True |
| 57 | ) |
nothing calls this directly
no outgoing calls
no test coverage detected