Skip to content

Add debug logging? #73

Description

@eihli

Aside from the print statements and wandb output, it might be nice for development and debugging to have the option to turn on verbose debug logs.

I've used something like below in the past. Put that in a root level __init__.py file and then in every other file you just import logging; logger = logging.getLogger(__name__); logger.debug(f'foobar')

import logging
import logging.config

LOG_FORMAT = "%(asctime)s %(pathname)s %(lineno)s {}".format(logging.BASIC_FORMAT)

log_level = getattr(logging, os.environ.get('PY_LOG_LVL', 'WARNING').upper())
logging_config = {
    'version': 1,
    'formatters': {
        'standard': {
            'format': LOG_FORMAT,
        },
    },
    'handlers': {
        'default': {
            'level': log_level,
            'formatter': 'standard',
            'class': 'logging.StreamHandler',
        },
    },
    'loggers': {
        '': {
            'handlers': ['default'],
            'level': log_level,
            'propagate': True,
        },
    },
}

logging.config.dictConfig(logging_config)

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