Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PATCH] logging.config.fileConfig() compulsivly disable all existing loggers #47386

Closed
llucax mannequin opened this issue Jun 19, 2008 · 6 comments
Closed

[PATCH] logging.config.fileConfig() compulsivly disable all existing loggers #47386

llucax mannequin opened this issue Jun 19, 2008 · 6 comments
Assignees
Labels
stdlib Python modules in the Lib dir

Comments

@llucax
Copy link
Mannequin

llucax mannequin commented Jun 19, 2008

BPO 3136
Nosy @vsajip, @llucax, @anacrolix
Files
  • logging.config.disable_existing_loggers.patch: Add fileConfig() option to choose if you want to disable existing loggers (patch)
  • logging.config.disable_existing_loggers.doc.patch: Add some documentation on the new fileConfig() argument (to be applied to r64416 or higher)
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/vsajip'
    closed_at = <Date 2008-06-19.22:42:12.960>
    created_at = <Date 2008-06-19.01:02:01.148>
    labels = ['library']
    title = '[PATCH] logging.config.fileConfig() compulsivly disable all existing loggers'
    updated_at = <Date 2011-04-08.10:53:57.098>
    user = 'https://github.com/llucax'

    bugs.python.org fields:

    activity = <Date 2011-04-08.10:53:57.098>
    actor = 'anacrolix'
    assignee = 'vinay.sajip'
    closed = True
    closed_date = <Date 2008-06-19.22:42:12.960>
    closer = 'vinay.sajip'
    components = ['Library (Lib)']
    creation = <Date 2008-06-19.01:02:01.148>
    creator = 'llucax'
    dependencies = []
    files = ['10657', '10662']
    hgrepos = []
    issue_num = 3136
    keywords = ['patch']
    message_count = 6.0
    messages = ['68388', '68391', '68404', '68428', '68434', '68435']
    nosy_count = 3.0
    nosy_names = ['vinay.sajip', 'llucax', 'anacrolix']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = None
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue3136'
    versions = ['Python 2.5']

    @llucax
    Copy link
    Mannequin Author

    llucax mannequin commented Jun 19, 2008

    When using logging.config.fileConfig() in a large project, with several
    nested loggers, is very counterintuitive and annoying that this function
    disable all non-configured-via-fileConfig() loggers, because it forces
    the config file to configure *all* the loggers there, which makes the
    file unmaintainable, and throws the beauty of hierarchical loggers to
    the trash.

    Attached is a sample patch that adds a new option
    "disable_existing_loggers" to fileConfig() function (defaulting to True,
    to make it backward-compatible) to control this behavior. If you like
    the idea I can update the documentation and add some testcases too.

    You can see a simple example about the problem and solution here:
    log.py: http://pastebin.lugmen.org.ar/4204
    log.ini: http://pastebin.lugmen.org.ar/4205

    without the patch, the output is:
    logger:DEBUG: log debug
    logger:INFO: log info
    logger:WARNING: log warning
    logger:ERROR: log error
    logger:CRITICAL: log critical

    With the patch (and passing disable_existing_loggers=False to
    fileConfig()) yields this output:
    logger:DEBUG: log debug
    logger:INFO: log info
    logger:WARNING: log warning
    logger:ERROR: log error
    logger:CRITICAL: log critical
    logger.sublogger:DEBUG: sublog debug
    logger.sublogger:INFO: sublog info
    logger.sublogger:WARNING: sublog warning
    logger.sublogger:ERROR: sublog error
    logger.sublogger:CRITICAL: sublog critical

    As one could expect when reading the logging module docs:
    """
    getLogger() returns a reference to a logger instance with the specified
    if it it is provided, or root if not. The names are period-separated
    hierarchical structures. Multiple calls to getLogger() with the same
    name will return a reference to the same logger object. Loggers that are
    further down in the hierarchical list are children of loggers higher up
    in the list. For example, given a logger with a name of foo, loggers
    with names of foo.bar, foo.bar.baz, and foo.bam are all children of foo.
    Child loggers propagate messages up to their parent loggers. Because of
    this, it is unnecessary to define and configure all the loggers an
    application uses. It is sufficient to configure a top-level logger and
    create child loggers as needed.
    """

    @llucax llucax mannequin added the stdlib Python modules in the Lib dir label Jun 19, 2008
    @vsajip
    Copy link
    Member

    vsajip commented Jun 19, 2008

    Without the patch, but simply moving the fileConfig() call to above
    where the loggers are initialised, the output is the same as your
    patched sample, viz.

    logger:DEBUG: log debug
    logger:INFO: log info
    logger:WARNING: log warning
    logger:ERROR: log error
    logger:CRITICAL: log critical
    logger.sublogger:DEBUG: sublog debug
    logger.sublogger:INFO: sublog info
    logger.sublogger:WARNING: sublog warning
    logger.sublogger:ERROR: sublog error
    logger.sublogger:CRITICAL: sublog critical

    See

    http://pastebin.lugmen.org.ar/4208

    @vsajip vsajip added the invalid label Jun 19, 2008
    @llucax
    Copy link
    Mannequin Author

    llucax mannequin commented Jun 19, 2008

    The problem is you can't always do that call before using the loggers.

    In my case, I get the logging config file via command-line arguments
    (using optparse), but before I can't even know what logging config file
    to load, I have log calls.

    Please reopen the bug, the actual solution is not flexible enough.

    @vsajip
    Copy link
    Member

    vsajip commented Jun 19, 2008

    Fixed checked into trunk.

    @vsajip vsajip closed this as completed Jun 19, 2008
    @vsajip vsajip removed the invalid label Jun 19, 2008
    @llucax
    Copy link
    Mannequin Author

    llucax mannequin commented Jun 20, 2008

    Thank you very much

    @llucax
    Copy link
    Mannequin Author

    llucax mannequin commented Jun 20, 2008

    Here is a patch to add some documentation on the new fileConfig()
    argument. Is not much, but it's better than nothing =)

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant