1# Verbose, notice, and spam log levels for Python's logging module.
2#
3# Author: Glenn Matthews <glenn@e-dad.net>
4# Last Change: August 7, 2017
5# URL: https://verboselogs.readthedocs.io
6
7"""
8Pylint_ plugin to fix invalid errors about the :mod:`logging` module.
9
10.. _Pylint: https://pypi.python.org/pypi/pylint
11"""
12
13from astroid import MANAGER, scoped_nodes, nodes
14
15
16def register(linter):
17    """No-op (required by Pylint)."""
18
19
20def verboselogs_class_transform(cls):
21    """Make Pylint aware of our custom logger methods."""
22    if cls.name == 'RootLogger':
23        for meth in ['notice', 'spam', 'success', 'verbose']:
24            cls.locals[meth] = [scoped_nodes.Function(meth, None)]
25
26
27def verboselogs_module_transform(mod):
28    """Make Pylint aware of our custom log levels."""
29    if mod.name == 'logging':
30        for const in ['NOTICE', 'SPAM', 'SUCCESS', 'VERBOSE']:
31            mod.locals[const] = [nodes.Const(const)]
32
33
34# Register the above methods with Pylint.
35MANAGER.register_transform(scoped_nodes.Class, verboselogs_class_transform)
36MANAGER.register_transform(scoped_nodes.Module, verboselogs_module_transform)
37