Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(131)

Side by Side Diff: third_party/logilab/common/logging_ext.py

Issue 739393004: Revert "Revert "pylint: upgrade to 1.3.1"" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools/
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « third_party/logilab/common/hg.py ('k') | third_party/logilab/common/modutils.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # -*- coding: utf-8 -*- 1 # -*- coding: utf-8 -*-
2 # copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved. 2 # copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
3 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr 3 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
4 # 4 #
5 # This file is part of logilab-common. 5 # This file is part of logilab-common.
6 # 6 #
7 # logilab-common is free software: you can redistribute it and/or modify it unde r 7 # logilab-common is free software: you can redistribute it and/or modify it unde r
8 # the terms of the GNU Lesser General Public License as published by the Free 8 # the terms of the GNU Lesser General Public License as published by the Free
9 # Software Foundation, either version 2.1 of the License, or (at your option) an y 9 # Software Foundation, either version 2.1 of the License, or (at your option) an y
10 # later version. 10 # later version.
11 # 11 #
12 # logilab-common is distributed in the hope that it will be useful, but WITHOUT 12 # logilab-common is distributed in the hope that it will be useful, but WITHOUT
13 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 14 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
15 # details. 15 # details.
16 # 16 #
17 # You should have received a copy of the GNU Lesser General Public License along 17 # You should have received a copy of the GNU Lesser General Public License along
18 # with logilab-common. If not, see <http://www.gnu.org/licenses/>. 18 # with logilab-common. If not, see <http://www.gnu.org/licenses/>.
19 """Extends the logging module from the standard library.""" 19 """Extends the logging module from the standard library."""
20 20
21 __docformat__ = "restructuredtext en" 21 __docformat__ = "restructuredtext en"
22 22
23 import os 23 import os
24 import sys 24 import sys
25 import logging 25 import logging
26 26
27 from six import string_types
28
27 from logilab.common.textutils import colorize_ansi 29 from logilab.common.textutils import colorize_ansi
28 30
29 31
30 def set_log_methods(cls, logger): 32 def set_log_methods(cls, logger):
31 """bind standard logger's methods as methods on the class""" 33 """bind standard logger's methods as methods on the class"""
32 cls.__logger = logger 34 cls.__logger = logger
33 for attr in ('debug', 'info', 'warning', 'error', 'critical', 'exception'): 35 for attr in ('debug', 'info', 'warning', 'error', 'critical', 'exception'):
34 setattr(cls, attr, getattr(logger, attr)) 36 setattr(cls, attr, getattr(logger, attr))
35 37
36 38
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 handler = logging.StreamHandler() 107 handler = logging.StreamHandler()
106 elif logfile is None: 108 elif logfile is None:
107 if syslog: 109 if syslog:
108 from logging import handlers 110 from logging import handlers
109 handler = handlers.SysLogHandler() 111 handler = handlers.SysLogHandler()
110 else: 112 else:
111 handler = logging.StreamHandler() 113 handler = logging.StreamHandler()
112 else: 114 else:
113 try: 115 try:
114 if rotation_parameters is None: 116 if rotation_parameters is None:
115 handler = logging.FileHandler(logfile) 117 if os.name == 'posix' and sys.version_info >= (2, 6):
118 from logging.handlers import WatchedFileHandler
119 handler = WatchedFileHandler(logfile)
120 else:
121 handler = logging.FileHandler(logfile)
116 else: 122 else:
117 from logging.handlers import TimedRotatingFileHandler 123 from logging.handlers import TimedRotatingFileHandler
118 handler = TimedRotatingFileHandler( 124 handler = TimedRotatingFileHandler(
119 logfile, **rotation_parameters) 125 logfile, **rotation_parameters)
120 except IOError: 126 except IOError:
121 handler = logging.StreamHandler() 127 handler = logging.StreamHandler()
122 return handler 128 return handler
123 129
124 def get_threshold(debug=False, logthreshold=None): 130 def get_threshold(debug=False, logthreshold=None):
125 if logthreshold is None: 131 if logthreshold is None:
126 if debug: 132 if debug:
127 logthreshold = logging.DEBUG 133 logthreshold = logging.DEBUG
128 else: 134 else:
129 logthreshold = logging.ERROR 135 logthreshold = logging.ERROR
130 elif isinstance(logthreshold, basestring): 136 elif isinstance(logthreshold, string_types):
131 logthreshold = getattr(logging, THRESHOLD_MAP.get(logthreshold, 137 logthreshold = getattr(logging, THRESHOLD_MAP.get(logthreshold,
132 logthreshold)) 138 logthreshold))
133 return logthreshold 139 return logthreshold
134 140
141 def _colorable_terminal():
142 isatty = hasattr(sys.__stdout__, 'isatty') and sys.__stdout__.isatty()
143 if not isatty:
144 return False
145 if os.name == 'nt':
146 try:
147 from colorama import init as init_win32_colors
148 except ImportError:
149 return False
150 init_win32_colors()
151 return True
152
135 def get_formatter(logformat=LOG_FORMAT, logdateformat=LOG_DATE_FORMAT): 153 def get_formatter(logformat=LOG_FORMAT, logdateformat=LOG_DATE_FORMAT):
136 isatty = hasattr(sys.__stdout__, 'isatty') and sys.__stdout__.isatty() 154 if _colorable_terminal():
137 if isatty and sys.platform != 'win32':
138 fmt = ColorFormatter(logformat, logdateformat) 155 fmt = ColorFormatter(logformat, logdateformat)
139 def col_fact(record): 156 def col_fact(record):
140 if 'XXX' in record.message: 157 if 'XXX' in record.message:
141 return 'cyan' 158 return 'cyan'
142 if 'kick' in record.message: 159 if 'kick' in record.message:
143 return 'red' 160 return 'red'
144 fmt.colorfilters.append(col_fact) 161 fmt.colorfilters.append(col_fact)
145 else: 162 else:
146 fmt = logging.Formatter(logformat, logdateformat) 163 fmt = logging.Formatter(logformat, logdateformat)
147 return fmt 164 return fmt
(...skipping 21 matching lines...) Expand all
169 # map logilab.common.logger thresholds to logging thresholds 186 # map logilab.common.logger thresholds to logging thresholds
170 THRESHOLD_MAP = {'LOG_DEBUG': 'DEBUG', 187 THRESHOLD_MAP = {'LOG_DEBUG': 'DEBUG',
171 'LOG_INFO': 'INFO', 188 'LOG_INFO': 'INFO',
172 'LOG_NOTICE': 'INFO', 189 'LOG_NOTICE': 'INFO',
173 'LOG_WARN': 'WARNING', 190 'LOG_WARN': 'WARNING',
174 'LOG_WARNING': 'WARNING', 191 'LOG_WARNING': 'WARNING',
175 'LOG_ERR': 'ERROR', 192 'LOG_ERR': 'ERROR',
176 'LOG_ERROR': 'ERROR', 193 'LOG_ERROR': 'ERROR',
177 'LOG_CRIT': 'CRITICAL', 194 'LOG_CRIT': 'CRITICAL',
178 } 195 }
OLDNEW
« no previous file with comments | « third_party/logilab/common/hg.py ('k') | third_party/logilab/common/modutils.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698