MCPcopy
hub / github.com/benoitc/gunicorn / setup

Method setup

gunicorn/glogging.py:195–265  ·  view source on GitHub ↗
(self, cfg)

Source from the content-addressed store, hash-verified

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,

Callers 2

__init__Method · 0.95
worker_classMethod · 0.45

Calls 7

_set_handlerMethod · 0.95
_set_syslog_handlerMethod · 0.95
copyMethod · 0.80
existsMethod · 0.80
getMethod · 0.45
filenoMethod · 0.45
loadMethod · 0.45

Tested by

no test coverage detected