From f98fd71782a8a7c10df8e474b6fa77b4b9d32d06 Mon Sep 17 00:00:00 2001 From: peterdudfield Date: Sun, 20 Oct 2024 19:27:23 +0100 Subject: [PATCH] simplify logging --- pvnet_app/app.py | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/pvnet_app/app.py b/pvnet_app/app.py index 8c7219c..5bc6b53 100644 --- a/pvnet_app/app.py +++ b/pvnet_app/app.py @@ -62,20 +62,14 @@ def filter(self, record): # Create a logger -logger = logging.getLogger() -logger.setLevel(logging.INFO) - -formatter = logging.Formatter( - fmt="[%(asctime)s] {%(pathname)s:%(lineno)d} %(levelname)s - %(message)s" +logging.basicConfig( + level=getattr(logging, os.getenv("LOGLEVEL", "DEBUG")), + format="[%(asctime)s] {%(pathname)s:%(lineno)d} %(levelname)s - %(message)s", ) -stream_handler = logging.StreamHandler() -stream_handler.setFormatter(formatter) -logger.addHandler(stream_handler) +logger = logging.getLogger() # Get rid of the verbose sqlalchemy logs -stream_handler.addFilter(SQLAlchemyFilter()) -sql_logger = logging.getLogger("sqlalchemy.engine.Engine") -sql_logger.addHandler(logging.NullHandler()) +logging.getLogger('sqlalchemy').setLevel(logging.ERROR) # ---------------------------------------------------------------------------