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

Implement a flexible logging framework for using f3dasm as a library or as an application #171

Open
1 of 3 tasks
GuillaumeBroggi opened this issue Sep 21, 2023 · 0 comments
Labels

Comments

@GuillaumeBroggi
Copy link
Contributor

GuillaumeBroggi commented Sep 21, 2023

Motivation

@BernardoFerreira

The best default behavior for loggers is to hand over to the user the responsibility of defining log handlers (see Python documentation).

f3dasm may be used as an application or as a library. A default logging behavior is suitable when f3dasm is used as an application (current implementation). However, this is not suitable when used as a library because the logging configuration may overlap / be in conflict with the logging configuration wished by the user.

Description

Commit 3cd4d1e proposes a more flexible framework where the existence of a logger is checked when initializing f3dasm. Then, if the user wishes to define his own logging configuration, he simply has to get a logger with f3dasm name before importing f3dasm. Otherwise, f3dasm loads the default behavior from a config file avoiding the use of the basicConfig() method.

The default behavior is similar to the existing implementation: logs are printed to stderr when level is above INFO. In addition, logs ares saved to a "f3dasm.log" file.

Behavior

import logging

logging.basicConfig(level=logging.INFO)

logger = logging.getLogger("f3dsam")
logger.setLevel(logging.INFO)
logger.propagate = False
formatter = logging.Formatter(fmt="My f3dsam logger - %(message)s")
stderr = logging.StreamHandler()
stderr.setLevel(logging.INFO)
stderr.setFormatter(formatter)
logger.addHandler(stderr)

import f3dasm

logging.info("Test log.")
>>> My f3dsam logger - Imported f3dasm (version: 1.4.0)
>>> INFO:root:Test log.
import logging

logging.basicConfig(level=logging.INFO)

import f3dasm

logging.info("Test log.")
>>> 2023-09-21 14:38:16,097 - f3dsam - Imported f3dasm (version: 1.4.0)
>>> INFO:root:Test log.

Tasks

  • Implement framework
  • Discuss behavior
  • Document behavior
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant