Skip to content

Agree on a "printing and logging" convention for PyKE #88

@barentsen

Description

@barentsen

We need a convention on how PyKE should deal with printing feedback to the users and writing logfiles. The current system based on verbose and logfile arguments is not in line with the logging mechanisms used by major scientific packages. I propose the following:

Main principles

  • There shall be no print statements anywhere.
  • All user feedback messages shall be delivered via a new keplog.log(level, message) function, which in turn shall make use of either Python's or AstroPy's built-in logging framework, which support different levels of logging (ERROR, WARNING, INFO, DEBUG).

Consequences

  • The verbose arguments shall be removed in favor of the config mechanisms provided by the logging framework. A convenience function called keplog.set_level can be added to help users set the log level (e.g. keplog.set_level(DEBUG)). The command-line tools can have a user-friendly --silent or --debug option to set the log level to ERROR or DEBUG, respectively.
  • All logfile arguments shall be removed in favor of the config mechanisms offered by the logging framework. A convenience function called e.g. keplog.set_logfile can be added to help users divert output to a logfile.

Other conventions

  • Whenever PyKE writes a file, it must be reported to the user via keplog.log(INFO, "Writing " + filename).
  • Progressbars shall have their desc and disable argument set, i.e.
    tqdm(iterable, desc="Informative description", disable=(keplog.get_level() <= INFO))
  • Command-line tools should catch all exceptions and print them via keplog.log(ERROR, msg).

What do y'all think?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions