Skip to content

Add logging example? #9

Closed
Closed

Description

@jvdzwaan

Is it a good idea to add a basic example of how to setup logging?

Activity

  1. bouweandela commented on Jul 5, 2018

    @bouweandela
    Member

    Yes, I would say so, having a logger configured immediately really helps to draw people's attention to the fact that they should use a logger instead of printing everything. I usually have something like this:

    logging.basicConfig(format="%(asctime)s [%(process)d] %(levelname)-8s "
                        "%(name)s,%(lineno)s\t%(message)s")
    logging.getLogger().setLevel('INFO')
    

    (usually I add a command line option to specify the log level) and have

    logger = logging.getLogger(__name__)
    

    at the top of every file where I need to log stuff.

  2. bouweandela commented on Jul 6, 2018

    @bouweandela
    Member

    The above example is for a program, for libraries you might want something a bit different. For programs it would be nice to also add an entry point and a default command line parser that displays a help and the version number, e.g. using click or argparse.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions