|
9 | 9 | import base64 |
10 | 10 | import binascii |
11 | 11 | import datetime |
12 | | -import json |
13 | 12 | import logging |
14 | 13 | import time |
15 | 14 | from typing import TYPE_CHECKING, Any |
|
19 | 18 | import sys # noqa: E402 |
20 | 19 | import threading # noqa: E402 |
21 | 20 | import traceback # noqa: E402 |
22 | | -from logging.config import dictConfig # noqa: E402 |
23 | 21 |
|
24 | 22 | from . import util # noqa: E402 |
25 | 23 |
|
|
28 | 26 |
|
29 | 27 | from .config import Config |
30 | 28 |
|
31 | | -# syslog facility codes |
32 | | -CONFIG_DEFAULTS = { |
33 | | - "version": 1, |
34 | | - "disable_existing_loggers": False, |
35 | | - "root": {"level": "INFO", "handlers": ["console"]}, |
36 | | - "loggers": { |
37 | | - "plain.server.error": { |
38 | | - "level": "INFO", |
39 | | - "handlers": ["error_console"], |
40 | | - "propagate": True, |
41 | | - "qualname": "plain.server.error", |
42 | | - }, |
43 | | - "plain.server.access": { |
44 | | - "level": "INFO", |
45 | | - "handlers": ["console"], |
46 | | - "propagate": True, |
47 | | - "qualname": "plain.server.access", |
48 | | - }, |
49 | | - }, |
50 | | - "handlers": { |
51 | | - "console": { |
52 | | - "class": "logging.StreamHandler", |
53 | | - "formatter": "generic", |
54 | | - "stream": "ext://sys.stdout", |
55 | | - }, |
56 | | - "error_console": { |
57 | | - "class": "logging.StreamHandler", |
58 | | - "formatter": "generic", |
59 | | - "stream": "ext://sys.stderr", |
60 | | - }, |
61 | | - }, |
62 | | - "formatters": { |
63 | | - "generic": { |
64 | | - "format": "%(asctime)s [%(process)d] [%(levelname)s] %(message)s", |
65 | | - "datefmt": "[%Y-%m-%d %H:%M:%S %z]", |
66 | | - "class": "logging.Formatter", |
67 | | - } |
68 | | - }, |
69 | | -} |
70 | | - |
71 | 29 |
|
72 | 30 | def loggers() -> list[logging.Logger]: |
73 | 31 | """get list of all loggers""" |
@@ -137,35 +95,18 @@ def setup(self, cfg: Config) -> None: |
137 | 95 | self._set_handler( |
138 | 96 | self.error_log, |
139 | 97 | cfg.errorlog, |
140 | | - logging.Formatter(self.error_fmt, self.datefmt), |
| 98 | + logging.Formatter(cfg.log_format, self.datefmt), |
141 | 99 | ) |
142 | 100 |
|
143 | 101 | # set plain.server.access handler |
144 | 102 | if cfg.accesslog is not None: |
145 | 103 | self._set_handler( |
146 | 104 | self.access_log, |
147 | 105 | cfg.accesslog, |
148 | | - fmt=logging.Formatter(self.access_fmt), |
| 106 | + fmt=logging.Formatter(cfg.log_format, self.datefmt), |
149 | 107 | stream=sys.stdout, |
150 | 108 | ) |
151 | 109 |
|
152 | | - # Apply logconfig_json if provided |
153 | | - if cfg.logconfig_json: |
154 | | - config = CONFIG_DEFAULTS.copy() |
155 | | - if os.path.exists(cfg.logconfig_json): |
156 | | - try: |
157 | | - config_json = json.load(open(cfg.logconfig_json)) |
158 | | - config.update(config_json) |
159 | | - dictConfig(config) |
160 | | - except ( |
161 | | - json.JSONDecodeError, |
162 | | - AttributeError, |
163 | | - ImportError, |
164 | | - ValueError, |
165 | | - TypeError, |
166 | | - ) as exc: |
167 | | - raise RuntimeError(str(exc)) |
168 | | - |
169 | 110 | def critical(self, msg: str, *args: Any, **kwargs: Any) -> None: |
170 | 111 | self.error_log.critical(msg, *args, **kwargs) |
171 | 112 |
|
@@ -261,7 +202,7 @@ def access( |
261 | 202 | for format details |
262 | 203 | """ |
263 | 204 |
|
264 | | - if not (self.cfg.accesslog or self.cfg.logconfig_json): |
| 205 | + if not self.cfg.accesslog: |
265 | 206 | return None |
266 | 207 |
|
267 | 208 | # wrap atoms: |
|
0 commit comments