| 49 | |
| 50 | |
| 51 | class WSGIErrorsWrapper(io.RawIOBase): |
| 52 | |
| 53 | def __init__(self, cfg): |
| 54 | # There is no public __init__ method for RawIOBase so |
| 55 | # we don't need to call super() in the __init__ method. |
| 56 | # pylint: disable=super-init-not-called |
| 57 | errorlog = logging.getLogger("gunicorn.error") |
| 58 | handlers = errorlog.handlers |
| 59 | self.streams = [] |
| 60 | |
| 61 | if cfg.errorlog == "-": |
| 62 | self.streams.append(sys.stderr) |
| 63 | handlers = handlers[1:] |
| 64 | |
| 65 | for h in handlers: |
| 66 | if hasattr(h, "stream"): |
| 67 | self.streams.append(h.stream) |
| 68 | |
| 69 | def write(self, data): |
| 70 | for stream in self.streams: |
| 71 | try: |
| 72 | stream.write(data) |
| 73 | except UnicodeError: |
| 74 | stream.write(data.encode("UTF-8")) |
| 75 | stream.flush() |
| 76 | |
| 77 | |
| 78 | def base_environ(cfg): |