Index: third_party/WebKit/Tools/Scripts/webkitpy/common/system/logutils.py |
diff --git a/third_party/WebKit/Tools/Scripts/webkitpy/common/system/logutils.py b/third_party/WebKit/Tools/Scripts/webkitpy/common/system/logutils.py |
index d1e91ec3e44f5c22e234f11a0c190cff054d64f1..b105b32fa50b6767d07ad0f11fc7b75210871148 100644 |
--- a/third_party/WebKit/Tools/Scripts/webkitpy/common/system/logutils.py |
+++ b/third_party/WebKit/Tools/Scripts/webkitpy/common/system/logutils.py |
@@ -22,106 +22,11 @@ |
"""Supports webkitpy logging.""" |
-# FIXME: Move this file to webkitpy/python24 since logging needs to |
-# be configured prior to running version-checking code. |
- |
import logging |
-import os |
import sys |
-import webkitpy |
- |
- |
_log = logging.getLogger(__name__) |
-# We set these directory paths lazily in get_logger() below. |
-_scripts_dir = "" |
-"""The normalized, absolute path to the ...Scripts directory.""" |
- |
-_webkitpy_dir = "" |
-"""The normalized, absolute path to the ...Scripts/webkitpy directory.""" |
- |
- |
-def _normalize_path(path): |
- """Return the given path normalized. |
- |
- Converts a path to an absolute path, removes any trailing slashes, |
- removes any extension, and lower-cases it. |
- """ |
- path = os.path.abspath(path) |
- path = os.path.normpath(path) |
- path = os.path.splitext(path)[0] # Remove the extension, if any. |
- path = path.lower() |
- |
- return path |
- |
- |
-# Observe that the implementation of this function does not require |
-# the use of any hard-coded strings like "webkitpy", etc. |
-# |
-# The main benefit this function has over using-- |
-# |
-# _log = logging.getLogger(__name__) |
-# |
-# is that get_logger() returns the same value even if __name__ is |
-# "__main__" -- i.e. even if the module is the script being executed |
-# from the command-line. |
-def get_logger(path): |
- """Return a logging.logger for the given path. |
- |
- Returns: |
- A logger whose name is the name of the module corresponding to |
- the given path. If the module is in webkitpy, the name is |
- the fully-qualified dotted module name beginning with webkitpy.... |
- Otherwise, the name is the base name of the module (i.e. without |
- any dotted module name prefix). |
- |
- Args: |
- path: The path of the module. Normally, this parameter should be |
- the __file__ variable of the module. |
- |
- Sample usage: |
- |
- from webkitpy.common.system import logutils |
- |
- _log = logutils.get_logger(__file__) |
- """ |
- # Since we assign to _scripts_dir and _webkitpy_dir in this function, |
- # we need to declare them global. |
- global _scripts_dir |
- global _webkitpy_dir |
- |
- path = _normalize_path(path) |
- |
- # Lazily evaluate _webkitpy_dir and _scripts_dir. |
- if not _scripts_dir: |
- # The normalized, absolute path to ...Scripts/webkitpy/__init__. |
- webkitpy_path = _normalize_path(webkitpy.__file__) |
- |
- _webkitpy_dir = os.path.split(webkitpy_path)[0] |
- _scripts_dir = os.path.split(_webkitpy_dir)[0] |
- |
- if path.startswith(_webkitpy_dir): |
- # Remove the initial Scripts directory portion, so the path |
- # starts with /webkitpy, for example "/webkitpy/init/logutils". |
- path = path[len(_scripts_dir):] |
- |
- parts = [] |
- while True: |
- (path, tail) = os.path.split(path) |
- if not tail: |
- break |
- parts.insert(0, tail) |
- |
- logger_name = ".".join(parts) # For example, webkitpy.common.system.logutils. |
- else: |
- # The path is outside of webkitpy. Default to the basename |
- # without the extension. |
- basename = os.path.basename(path) |
- logger_name = os.path.splitext(basename)[0] |
- |
- return logging.getLogger(logger_name) |
- |
def _default_handlers(stream, logging_level): |
"""Return a list of the default logging handlers to use. |