Skip to content

Commit 77524a3

Browse files
committed
Added a management command to list registered loggers, in order to see which can be configured in settings_local with the UTILS_LOGGER_LEVELS settings.
- Legacy-Id: 17974
1 parent 6820363 commit 77524a3

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Copyright The IETF Trust 2020, All Rights Reserved
2+
# -*- coding: utf-8 -*-
3+
4+
import logging_tree
5+
import os
6+
7+
from textwrap import dedent
8+
9+
from django.core.management.base import BaseCommand
10+
11+
import debug # pyflakes:ignore
12+
13+
class Command(BaseCommand):
14+
"""
15+
Display a list or tree representation of python loggers.<BR>
16+
17+
Add a UTILS_LOGGER_LEVELS setting in settings_local.py to configure
18+
non-default logging levels for any registered logger, for instance:
19+
20+
UTILS_LOGGER_LEVELS = {
21+
'oicd_provider': 'DEBUG',
22+
'urllib3.connection': 'DEBUG',
23+
}
24+
25+
"""
26+
27+
help = dedent(__doc__).strip()
28+
29+
def add_arguments(self, parser):
30+
parser.add_argument('--tree', action="store_true", default=False,
31+
help='Only list loggers found, without showing the full tree.')
32+
33+
def handle(self, *filenames, **options):
34+
if options.get('tree'):
35+
self.stdout.write(logging_tree.format.build_description(node=None))
36+
else:
37+
self.stdout.write("Registered logging.Logger instances by name:")
38+
def show(node):
39+
if len(node) == 3:
40+
name, logger, nodes = node
41+
self.stdout.write(" %s" % (name or ''))
42+
for node in nodes:
43+
show(node)
44+
else:
45+
self.stdout.write('Node: %s' % node)
46+
show(logging_tree.tree())
47+
self.stdout.write("\nUse '%s --tree' to show the full logger tree" % os.path.splitext(os.path.basename(__file__))[0])

0 commit comments

Comments
 (0)