mirror of
https://github.com/frappe/gunicorn.git
synced 2026-01-14 11:09:11 +08:00
make sure to redirect wsgi.errors when needed
By if the options ` --error-logfile` is set to '-' then wsgi.errors are returned to sys.stderr, if any log file is passed either using the log-config file or the option, Errors are written to the files. By default no error is returned.
This commit is contained in:
parent
03a6136083
commit
ee08ac8644
@ -3,6 +3,7 @@
|
||||
# This file is part of gunicorn released under the MIT license.
|
||||
# See the NOTICE for more information.
|
||||
|
||||
import io
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
@ -42,10 +43,35 @@ class FileWrapper(object):
|
||||
raise IndexError
|
||||
|
||||
|
||||
class WSGIErrorsWraper(io.RawIOBase):
|
||||
|
||||
def __init__(self, cfg):
|
||||
errorlog = logging.getLogger("gunicorn.error")
|
||||
self.streams = []
|
||||
|
||||
if cfg.errorlog == "-":
|
||||
self.streams.append(sys.stderr)
|
||||
|
||||
for h in errorlog.handlers:
|
||||
if hasattr(h, "stream"):
|
||||
self.streams.append(h.stream)
|
||||
|
||||
if not self.streams:
|
||||
self.streams.append(sys.stderr)
|
||||
|
||||
def write(self, data):
|
||||
for stream in self.streams:
|
||||
try:
|
||||
stream.write(data)
|
||||
except UnicodeError:
|
||||
stream.write(data.encode("UTF-8"))
|
||||
stream.flush()
|
||||
|
||||
|
||||
def default_environ(req, sock, cfg):
|
||||
return {
|
||||
"wsgi.input": req.body,
|
||||
"wsgi.errors": sys.stderr,
|
||||
"wsgi.errors": WSGIErrorsWraper(cfg),
|
||||
"wsgi.version": (1, 0),
|
||||
"wsgi.multithread": False,
|
||||
"wsgi.multiprocess": (cfg.workers > 1),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user