| OLD | NEW |
| 1 # Copyright (C) 2010 Chris Jerdonek (cjerdonek@webkit.org) | 1 # Copyright (C) 2010 Chris Jerdonek (cjerdonek@webkit.org) |
| 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 | 4 # modification, are permitted provided that the following conditions |
| 5 # are met: | 5 # are met: |
| 6 # 1. Redistributions of source code must retain the above copyright | 6 # 1. Redistributions of source code must retain the above copyright |
| 7 # notice, this list of conditions and the following disclaimer. | 7 # notice, this list of conditions and the following disclaimer. |
| 8 # 2. Redistributions in binary form must reproduce the above copyright | 8 # 2. Redistributions in binary form must reproduce the above copyright |
| 9 # notice, this list of conditions and the following disclaimer in the | 9 # notice, this list of conditions and the following disclaimer in the |
| 10 # documentation and/or other materials provided with the distribution. | 10 # documentation and/or other materials provided with the distribution. |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 | 40 |
| 41 _webkitpy_dir = "" | 41 _webkitpy_dir = "" |
| 42 """The normalized, absolute path to the ...Scripts/webkitpy directory.""" | 42 """The normalized, absolute path to the ...Scripts/webkitpy directory.""" |
| 43 | 43 |
| 44 | 44 |
| 45 def _normalize_path(path): | 45 def _normalize_path(path): |
| 46 """Return the given path normalized. | 46 """Return the given path normalized. |
| 47 | 47 |
| 48 Converts a path to an absolute path, removes any trailing slashes, | 48 Converts a path to an absolute path, removes any trailing slashes, |
| 49 removes any extension, and lower-cases it. | 49 removes any extension, and lower-cases it. |
| 50 | |
| 51 """ | 50 """ |
| 52 path = os.path.abspath(path) | 51 path = os.path.abspath(path) |
| 53 path = os.path.normpath(path) | 52 path = os.path.normpath(path) |
| 54 path = os.path.splitext(path)[0] # Remove the extension, if any. | 53 path = os.path.splitext(path)[0] # Remove the extension, if any. |
| 55 path = path.lower() | 54 path = path.lower() |
| 56 | 55 |
| 57 return path | 56 return path |
| 58 | 57 |
| 59 | 58 |
| 60 # Observe that the implementation of this function does not require | 59 # Observe that the implementation of this function does not require |
| (...skipping 18 matching lines...) Expand all Loading... |
| 79 | 78 |
| 80 Args: | 79 Args: |
| 81 path: The path of the module. Normally, this parameter should be | 80 path: The path of the module. Normally, this parameter should be |
| 82 the __file__ variable of the module. | 81 the __file__ variable of the module. |
| 83 | 82 |
| 84 Sample usage: | 83 Sample usage: |
| 85 | 84 |
| 86 from webkitpy.common.system import logutils | 85 from webkitpy.common.system import logutils |
| 87 | 86 |
| 88 _log = logutils.get_logger(__file__) | 87 _log = logutils.get_logger(__file__) |
| 89 | |
| 90 """ | 88 """ |
| 91 # Since we assign to _scripts_dir and _webkitpy_dir in this function, | 89 # Since we assign to _scripts_dir and _webkitpy_dir in this function, |
| 92 # we need to declare them global. | 90 # we need to declare them global. |
| 93 global _scripts_dir | 91 global _scripts_dir |
| 94 global _webkitpy_dir | 92 global _webkitpy_dir |
| 95 | 93 |
| 96 path = _normalize_path(path) | 94 path = _normalize_path(path) |
| 97 | 95 |
| 98 # Lazily evaluate _webkitpy_dir and _scripts_dir. | 96 # Lazily evaluate _webkitpy_dir and _scripts_dir. |
| 99 if not _scripts_dir: | 97 if not _scripts_dir: |
| (...skipping 23 matching lines...) Expand all Loading... |
| 123 logger_name = os.path.splitext(basename)[0] | 121 logger_name = os.path.splitext(basename)[0] |
| 124 | 122 |
| 125 return logging.getLogger(logger_name) | 123 return logging.getLogger(logger_name) |
| 126 | 124 |
| 127 | 125 |
| 128 def _default_handlers(stream, logging_level): | 126 def _default_handlers(stream, logging_level): |
| 129 """Return a list of the default logging handlers to use. | 127 """Return a list of the default logging handlers to use. |
| 130 | 128 |
| 131 Args: | 129 Args: |
| 132 stream: See the configure_logging() docstring. | 130 stream: See the configure_logging() docstring. |
| 133 | |
| 134 """ | 131 """ |
| 135 # Create the filter. | 132 # Create the filter. |
| 136 def should_log(record): | 133 def should_log(record): |
| 137 """Return whether a logging.LogRecord should be logged.""" | 134 """Return whether a logging.LogRecord should be logged.""" |
| 138 if record.name.startswith("webkitpy.thirdparty"): | 135 if record.name.startswith("webkitpy.thirdparty"): |
| 139 return False | 136 return False |
| 140 return True | 137 return True |
| 141 | 138 |
| 142 logging_filter = logging.Filter() | 139 logging_filter = logging.Filter() |
| 143 logging_filter.filter = should_log | 140 logging_filter.filter = should_log |
| (...skipping 27 matching lines...) Expand all Loading... |
| 171 logging.INFO. | 168 logging.INFO. |
| 172 logger: A logging.logger instance to configure. This parameter | 169 logger: A logging.logger instance to configure. This parameter |
| 173 should be used only in unit tests. Defaults to the | 170 should be used only in unit tests. Defaults to the |
| 174 root logger. | 171 root logger. |
| 175 stream: A file-like object to which to log used in creating the default | 172 stream: A file-like object to which to log used in creating the default |
| 176 handlers. The stream must define an "encoding" data attribute, | 173 handlers. The stream must define an "encoding" data attribute, |
| 177 or else logging raises an error. Defaults to sys.stderr. | 174 or else logging raises an error. Defaults to sys.stderr. |
| 178 handlers: A list of logging.Handler instances to add to the logger | 175 handlers: A list of logging.Handler instances to add to the logger |
| 179 being configured. If this parameter is provided, then the | 176 being configured. If this parameter is provided, then the |
| 180 stream parameter is not used. | 177 stream parameter is not used. |
| 181 | |
| 182 """ | 178 """ |
| 183 # If the stream does not define an "encoding" data attribute, the | 179 # If the stream does not define an "encoding" data attribute, the |
| 184 # logging module can throw an error like the following: | 180 # logging module can throw an error like the following: |
| 185 # | 181 # |
| 186 # Traceback (most recent call last): | 182 # Traceback (most recent call last): |
| 187 # File "/System/Library/Frameworks/Python.framework/Versions/2.6/... | 183 # File "/System/Library/Frameworks/Python.framework/Versions/2.6/... |
| 188 # lib/python2.6/logging/__init__.py", line 761, in emit | 184 # lib/python2.6/logging/__init__.py", line 761, in emit |
| 189 # self.stream.write(fs % msg.encode(self.stream.encoding)) | 185 # self.stream.write(fs % msg.encode(self.stream.encoding)) |
| 190 # LookupError: unknown encoding: unknown | 186 # LookupError: unknown encoding: unknown |
| 191 if logging_level is None: | 187 if logging_level is None: |
| 192 logging_level = logging.INFO | 188 logging_level = logging.INFO |
| 193 if logger is None: | 189 if logger is None: |
| 194 logger = logging.getLogger() | 190 logger = logging.getLogger() |
| 195 if stream is None: | 191 if stream is None: |
| 196 stream = sys.stderr | 192 stream = sys.stderr |
| 197 if handlers is None: | 193 if handlers is None: |
| 198 handlers = _default_handlers(stream, logging_level) | 194 handlers = _default_handlers(stream, logging_level) |
| 199 | 195 |
| 200 logger.setLevel(logging_level) | 196 logger.setLevel(logging_level) |
| 201 | 197 |
| 202 for handler in handlers: | 198 for handler in handlers: |
| 203 logger.addHandler(handler) | 199 logger.addHandler(handler) |
| 204 | 200 |
| 205 _log.debug("Debug logging enabled.") | 201 _log.debug("Debug logging enabled.") |
| 206 | 202 |
| 207 return handlers | 203 return handlers |
| OLD | NEW |