mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Merge branch 'suppress-brokenpipeerror' of https://github.com/keszybz/calibre
This commit is contained in:
commit
bc6e9cff20
@ -2,16 +2,12 @@
|
||||
# vim:fileencoding=utf-8
|
||||
# License: GPLv3 Copyright: 2009, Kovid Goyal <kovid at kovidgoyal.net>
|
||||
|
||||
'A simplified logging system'
|
||||
|
||||
DEBUG = 0
|
||||
INFO = 1
|
||||
WARN = 2
|
||||
ERROR = 3
|
||||
# A simplified logging system
|
||||
|
||||
import io
|
||||
import sys
|
||||
import traceback
|
||||
from contextlib import suppress
|
||||
from functools import partial
|
||||
from threading import Lock
|
||||
|
||||
@ -19,6 +15,12 @@ from calibre.prints import prints
|
||||
from polyglot.builtins import as_unicode
|
||||
|
||||
|
||||
DEBUG = 0
|
||||
INFO = 1
|
||||
WARN = 2
|
||||
ERROR = 3
|
||||
|
||||
|
||||
class Stream(object):
|
||||
|
||||
def __init__(self, stream=None):
|
||||
@ -31,6 +33,8 @@ class Stream(object):
|
||||
self._prints(text, end='')
|
||||
|
||||
def flush(self):
|
||||
with suppress(BrokenPipeError):
|
||||
# Don't fail if we were logging to a pipe and it got closed
|
||||
self.stream.flush()
|
||||
|
||||
def prints(self, level, *args, **kwargs):
|
||||
@ -61,9 +65,6 @@ class ANSIStream(Stream):
|
||||
with ColoredStream(self.stream, self.color[level]):
|
||||
self._prints(*args, **kwargs)
|
||||
|
||||
def flush(self):
|
||||
self.stream.flush()
|
||||
|
||||
|
||||
class FileStream(Stream):
|
||||
|
||||
@ -94,9 +95,6 @@ class HTMLStream(Stream):
|
||||
self._prints(*args, **kwargs)
|
||||
self._prints(self.normal, end='')
|
||||
|
||||
def flush(self):
|
||||
self.stream.flush()
|
||||
|
||||
|
||||
class UnicodeHTMLStream(HTMLStream):
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user