(self, cfg)
| 193 | self.setup(cfg) |
| 194 | |
| 195 | def setup(self, cfg): |
| 196 | self.loglevel = self.LOG_LEVELS.get(cfg.loglevel.lower(), logging.INFO) |
| 197 | self.error_log.setLevel(self.loglevel) |
| 198 | self.access_log.setLevel(logging.INFO) |
| 199 | |
| 200 | # set gunicorn.error handler |
| 201 | if self.cfg.capture_output and cfg.errorlog != "-": |
| 202 | for stream in sys.stdout, sys.stderr: |
| 203 | stream.flush() |
| 204 | |
| 205 | self.logfile = open(cfg.errorlog, 'a+') |
| 206 | os.dup2(self.logfile.fileno(), sys.stdout.fileno()) |
| 207 | os.dup2(self.logfile.fileno(), sys.stderr.fileno()) |
| 208 | |
| 209 | self._set_handler(self.error_log, cfg.errorlog, |
| 210 | logging.Formatter(self.error_fmt, self.datefmt)) |
| 211 | |
| 212 | # set gunicorn.access handler |
| 213 | if cfg.accesslog is not None: |
| 214 | self._set_handler( |
| 215 | self.access_log, cfg.accesslog, |
| 216 | fmt=logging.Formatter(self.access_fmt), stream=sys.stdout |
| 217 | ) |
| 218 | |
| 219 | # set syslog handler |
| 220 | if cfg.syslog: |
| 221 | self._set_syslog_handler( |
| 222 | self.error_log, cfg, self.syslog_fmt, "error" |
| 223 | ) |
| 224 | if not cfg.disable_redirect_access_to_syslog: |
| 225 | self._set_syslog_handler( |
| 226 | self.access_log, cfg, self.syslog_fmt, "access" |
| 227 | ) |
| 228 | |
| 229 | if cfg.logconfig_dict: |
| 230 | config = CONFIG_DEFAULTS.copy() |
| 231 | config.update(cfg.logconfig_dict) |
| 232 | try: |
| 233 | dictConfig(config) |
| 234 | except ( |
| 235 | AttributeError, |
| 236 | ImportError, |
| 237 | ValueError, |
| 238 | TypeError |
| 239 | ) as exc: |
| 240 | raise RuntimeError(str(exc)) from exc |
| 241 | elif cfg.logconfig_json: |
| 242 | config = CONFIG_DEFAULTS.copy() |
| 243 | if os.path.exists(cfg.logconfig_json): |
| 244 | try: |
| 245 | config_json = json.load(open(cfg.logconfig_json)) |
| 246 | config.update(config_json) |
| 247 | dictConfig(config) |
| 248 | except ( |
| 249 | json.JSONDecodeError, |
| 250 | AttributeError, |
| 251 | ImportError, |
| 252 | ValueError, |
no test coverage detected