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/.
7 class PerfDocLogger(object):
9 Logger for the PerfDoc tooling. Handles the warnings by outputting
10 them into through the StructuredLogger provided by lint.
19 """Initializes the PerfDocLogger."""
21 # Set up class attributes for all logger instances
22 if not PerfDocLogger
.LOGGER
:
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
34 :param str msg: Message to log.
38 def warning(self
, msg
, files
, restricted
=True):
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.
48 if type(files
) is not list:
52 self
.logger
.info("No file was provided for the warning")
53 self
.logger
.lint_error(
59 rule
="Flawless performance docs (unknown file)",
62 PerfDocLogger
.FAILED
= True
65 # Add a reviewbot error for each file that is given
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):
77 self
.logger
.lint_error(
81 path
=str(pathlib
.PurePosixPath(fpath
)),
83 rule
="Flawless performance docs.",
86 PerfDocLogger
.FAILED
= True
89 def critical(self
, msg
):
91 Log a critical message.
93 :param str msg: Message to log.
95 self
.logger
.critical(msg
)