datatracker/ietf/utils/management/commands/showloggers.py
Jennifer Richards 48e0aa23f5
refactor: clean up logging (#7419)
* fix: log to stdout/stderr in json format

* chore: remove UTILS_LOGGER_LEVELS

This is not used (there _is_ a setting for the
django.security logger in settings_local.py on
production, but it is redundant with the
settings.LOGGING configuration and is not doing
anything).

* chore: revert to debug_console django logging

* chore: log.log to syslog via datatracker logger

* chore: remove unused imports

---------

Co-authored-by: Robert Sparks <rjsparks@nostrum.com>
2024-05-14 18:47:40 -05:00

37 lines
1.3 KiB
Python

# Copyright The IETF Trust 2020, All Rights Reserved
# -*- coding: utf-8 -*-
import logging_tree
import os
from textwrap import dedent
from django.core.management.base import BaseCommand
import debug # pyflakes:ignore
class Command(BaseCommand):
"""Display a list or tree representation of python loggers"""
help = dedent(__doc__).strip()
def add_arguments(self, parser):
parser.add_argument('--tree', action="store_true", default=False,
help='Only list loggers found, without showing the full tree.')
def handle(self, *filenames, **options):
if options.get('tree'):
self.stdout.write(logging_tree.format.build_description(node=None))
else:
self.stdout.write("Registered logging.Logger instances by name:")
def show(node):
if len(node) == 3:
name, logger, nodes = node
self.stdout.write(" %s" % (name or ''))
for node in nodes:
show(node)
else:
self.stdout.write('Node: %s' % node)
show(logging_tree.tree())
self.stdout.write("\nUse '%s --tree' to show the full logger tree" % os.path.splitext(os.path.basename(__file__))[0])