diff --git a/linkcheck/logger/__init__.py b/linkcheck/logger/__init__.py index 18e29dc4..d8c1a35a 100644 --- a/linkcheck/logger/__init__.py +++ b/linkcheck/logger/__init__.py @@ -54,6 +54,14 @@ ContentTypes = dict( other=0, ) + +def get_stdout_writer (encoding=i18n.default_encoding, errors='replace'): + """Get wrapped sys.stdout writer with given encoding and error + handling.""" + Writer = codecs.getwriter(encoding) + return Writer(sys.stdout, errors) + + class LogStatistics (object): """Gather log statistics: - number of errors, warnings and valid links @@ -199,8 +207,8 @@ class Logger (object): elif 'fd' in args: self.fd = args['fd'] else: - Writer = codecs.getwriter(self.output_encoding) - self.fd = Writer(sys.stdout, self.codec_errors) + self.fd = get_stdout_writer(encoding=self.output_encoding, + errors=self.codec_errors) def start_fileoutput (self): """Start output to configured file."""