OLD | NEW |
1 # Copyright (C) 2010, 2012 Google Inc. All rights reserved. | 1 # Copyright (C) 2010, 2012 Google Inc. All rights reserved. |
2 # | 2 # |
3 # Redistribution and use in source and binary forms, with or without | 3 # Redistribution and use in source and binary forms, with or without |
4 # modification, are permitted provided that the following conditions are | 4 # modification, are permitted provided that the following conditions are |
5 # met: | 5 # met: |
6 # | 6 # |
7 # * Redistributions of source code must retain the above copyright | 7 # * Redistributions of source code must retain the above copyright |
8 # notice, this list of conditions and the following disclaimer. | 8 # notice, this list of conditions and the following disclaimer. |
9 # * Redistributions in binary form must reproduce the above | 9 # * Redistributions in binary form must reproduce the above |
10 # copyright notice, this list of conditions and the following disclaimer | 10 # copyright notice, this list of conditions and the following disclaimer |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 | 108 |
109 # This is the easiest way to make sure a byte stream is printable as asc
ii | 109 # This is the easiest way to make sure a byte stream is printable as asc
ii |
110 # with all non-ascii characters replaced. | 110 # with all non-ascii characters replaced. |
111 uni_msg = msg if isinstance(msg, unicode) else msg.decode('ascii', error
s='replace') | 111 uni_msg = msg if isinstance(msg, unicode) else msg.decode('ascii', error
s='replace') |
112 self._stream.write(uni_msg.encode('ascii', errors='replace')) | 112 self._stream.write(uni_msg.encode('ascii', errors='replace')) |
113 | 113 |
114 def writeln(self, txt, now=None, pid=None): | 114 def writeln(self, txt, now=None, pid=None): |
115 self.write(self._ensure_newline(txt), now, pid) | 115 self.write(self._ensure_newline(txt), now, pid) |
116 | 116 |
117 def _erase_last_partial_line(self): | 117 def _erase_last_partial_line(self): |
118 num_chars = len(self._last_partial_line) | |
119 self._stream.write(self._erasure(self._last_partial_line)) | 118 self._stream.write(self._erasure(self._last_partial_line)) |
120 self._last_partial_line = '' | 119 self._last_partial_line = '' |
121 | 120 |
122 def flush(self): | 121 def flush(self): |
123 if self._last_partial_line: | 122 if self._last_partial_line: |
124 self._stream.write('\n') | 123 self._stream.write('\n') |
125 self._last_partial_line = '' | 124 self._last_partial_line = '' |
126 self._stream.flush() | 125 self._stream.flush() |
127 | 126 |
128 def number_of_columns(self): | 127 def number_of_columns(self): |
129 return self._number_of_columns | 128 return self._number_of_columns |
130 | 129 |
131 | 130 |
132 class _LogHandler(logging.Handler): | 131 class _LogHandler(logging.Handler): |
133 | 132 |
134 def __init__(self, meter): | 133 def __init__(self, meter): |
135 logging.Handler.__init__(self) | 134 logging.Handler.__init__(self) |
136 self._meter = meter | 135 self._meter = meter |
137 self.name = LOG_HANDLER_NAME | 136 self.name = LOG_HANDLER_NAME |
138 | 137 |
139 def emit(self, record): | 138 def emit(self, record): |
140 self._meter.writeln(record.getMessage(), record.created, record.process) | 139 self._meter.writeln(record.getMessage(), record.created, record.process) |
OLD | NEW |