Skip to content

I am not happy with "Logging in a Library" #794

@guettli

Description

@guettli

I am not happy with "Logging in a Library"

http://docs.python-guide.org/en/latest/writing/logging/#logging-in-a-library

The following snippet is too long for my eyes:

# Set default logging handler to avoid "No handler found" warnings.
import logging
try:  # Python 2.7+
    from logging import NullHandler
except ImportError:
    class NullHandler(logging.Handler):
        def emit(self, record):
            pass

logging.getLogger(__name__).addHandler(NullHandler())

I guess only very few people need to support Python<2.7 today. I think a guide for new comers should use the pattern like this:

import logging
logging.getLogger(__name__).addHandler(logging.NullHandler())

My goal: less is more. Too much code confuses new comers.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions