Backed out changeset b71c8c052463 (bug 1943846) for causing mass failures. CLOSED...
[gecko.git] / tools / lint / perfdocs / logger.py
blobdb25fec682f0fa2f5d2bc32b8fc9646760086c23
1 # This Source Code Form is subject to the terms of the Mozilla Public
2 # License, v. 2.0. If a copy of the MPL was not distributed with this
3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
4 import pathlib
7 class PerfDocLogger(object):
8 """
9 Logger for the PerfDoc tooling. Handles the warnings by outputting
10 them into through the StructuredLogger provided by lint.
11 """
13 TOP_DIR = ""
14 PATHS = []
15 LOGGER = None
16 FAILED = False
18 def __init__(self):
19 """Initializes the PerfDocLogger."""
21 # Set up class attributes for all logger instances
22 if not PerfDocLogger.LOGGER:
23 raise Exception(
24 "Missing linting LOGGER instance for PerfDocLogger initialization"
26 if not PerfDocLogger.PATHS:
27 raise Exception("Missing PATHS for PerfDocLogger initialization")
28 self.logger = PerfDocLogger.LOGGER
30 def log(self, msg):
31 """
32 Log an info message.
34 :param str msg: Message to log.
35 """
36 self.logger.info(msg)
38 def warning(self, msg, files, restricted=True):
39 """
40 Logs a validation warning message. The warning message is
41 used as the error message that is output in the reviewbot.
43 :param str msg: Message to log, it's also used as the error message
44 for the issue that is output by the reviewbot.
45 :param list/str files: The file(s) that this warning is about.
46 :param boolean restricted: If the param is False, the lint error can be used anywhere.
47 """
48 if type(files) is not list:
49 files = [files]
51 if len(files) == 0:
52 self.logger.info("No file was provided for the warning")
53 self.logger.lint_error(
54 message=msg,
55 lineno=0,
56 column=None,
57 path=None,
58 linter="perfdocs",
59 rule="Flawless performance docs (unknown file)",
62 PerfDocLogger.FAILED = True
63 return
65 # Add a reviewbot error for each file that is given
66 for file in files:
67 # Get a relative path (reviewbot can't handle absolute paths)
68 fpath = str(file).replace(str(PerfDocLogger.TOP_DIR), "")
70 # Filter out any issues that do not relate to the paths
71 # that are being linted
72 for path in PerfDocLogger.PATHS:
73 if restricted and str(path) not in str(file):
74 continue
76 # Output error entry
77 self.logger.lint_error(
78 message=msg,
79 lineno=0,
80 column=None,
81 path=str(pathlib.PurePosixPath(fpath)),
82 linter="perfdocs",
83 rule="Flawless performance docs.",
86 PerfDocLogger.FAILED = True
87 break
89 def critical(self, msg):
90 """
91 Log a critical message.
93 :param str msg: Message to log.
94 """
95 self.logger.critical(msg)