| OLD | NEW |
| 1 # Copyright 2015 The Swarming Authors. All rights reserved. | 1 # Copyright 2015 The Swarming Authors. All rights reserved. |
| 2 # Use of this source code is governed under the Apache License, Version 2.0 that | 2 # Use of this source code is governed under the Apache License, Version 2.0 that |
| 3 # can be found in the LICENSE file. | 3 # can be found in the LICENSE file. |
| 4 | 4 |
| 5 """Utility relating to logging.""" | 5 """Utility relating to logging.""" |
| 6 | 6 |
| 7 import argparse | 7 import argparse |
| 8 import codecs | 8 import codecs |
| 9 import ctypes | 9 import ctypes |
| 10 import logging | 10 import logging |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 def formatTime(self, record, datefmt=None): | 146 def formatTime(self, record, datefmt=None): |
| 147 """Change is ',' to '.'.""" | 147 """Change is ',' to '.'.""" |
| 148 ct = self.converter(record.created) | 148 ct = self.converter(record.created) |
| 149 if datefmt: | 149 if datefmt: |
| 150 return time.strftime(datefmt, ct) | 150 return time.strftime(datefmt, ct) |
| 151 else: | 151 else: |
| 152 t = time.strftime("%Y-%m-%d %H:%M:%S", ct) | 152 t = time.strftime("%Y-%m-%d %H:%M:%S", ct) |
| 153 return "%s.%03d" % (t, record.msecs) | 153 return "%s.%03d" % (t, record.msecs) |
| 154 | 154 |
| 155 | 155 |
| 156 class Filter(logging.Filter): | 156 class Filter(object): |
| 157 """Adds fields used by the infra-specific formatter. | 157 """Adds fields used by the infra-specific formatter. |
| 158 | 158 |
| 159 Fields added: | 159 Fields added: |
| 160 - 'severity': one-letter indicator of log level (first letter of levelname). | 160 - 'severity': one-letter indicator of log level (first letter of levelname). |
| 161 """ | 161 """ |
| 162 | 162 |
| 163 def filter(self, record): | 163 def filter(self, record): |
| 164 record.severity = record.levelname[0] | 164 record.severity = record.levelname[0] |
| 165 return True | 165 return True |
| 166 | 166 |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 | 291 |
| 292 def parse_args(self, *args, **kwargs): | 292 def parse_args(self, *args, **kwargs): |
| 293 # Make sure this group is always the last one. | 293 # Make sure this group is always the last one. |
| 294 self._add_logging_group() | 294 self._add_logging_group() |
| 295 | 295 |
| 296 args = super(ArgumentParserWithLogging, self).parse_args(*args, **kwargs) | 296 args = super(ArgumentParserWithLogging, self).parse_args(*args, **kwargs) |
| 297 prepare_logging(self.enable_log_file and args.log_file, self.logger_root) | 297 prepare_logging(self.enable_log_file and args.log_file, self.logger_root) |
| 298 set_console_level( | 298 set_console_level( |
| 299 LEVELS[min(len(LEVELS) - 1, args.verbose)], self.logger_root) | 299 LEVELS[min(len(LEVELS) - 1, args.verbose)], self.logger_root) |
| 300 return args | 300 return args |
| OLD | NEW |