From c26aa1be434a4703f1ac91f397682a6be9c6db80 Mon Sep 17 00:00:00 2001 From: marcsello Date: Tue, 10 Aug 2021 16:15:20 +0200 Subject: [PATCH] some updates --- src/app.py | 37 ++++++++++++++++++++----------------- src/config.py | 8 ++++++++ 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/src/app.py b/src/app.py index 3dd0de7..c292881 100644 --- a/src/app.py +++ b/src/app.py @@ -21,21 +21,6 @@ __copyright__ = "Copyright 2020, Birbnetes Team" __module_name__ = "app" __version__text__ = "1" -if config.SENTRY_DSN: - sentry_logging = LoggingIntegration( - level=logging.DEBUG, # Capture info and above as breadcrumbs - event_level=logging.ERROR # Send errors as events - ) - sentry_sdk.init( - dsn=config.SENTRY_DSN, - send_default_pii=True, - integrations=[sentry_logging], - traces_sample_rate=1.0, - release=config.RELEASE_ID, - environment=config.RELEASEMODE, - _experiments={"auto_enabling_integrations": True} - ) - def setup_rabbit(mqtt_: MQTT) -> None: logging.info("Connecting to RabbitMQ...") @@ -118,15 +103,33 @@ def on_message_creator(mqtt_: MQTT): return on_message -if __name__ == "__main__": +def main(): logging.basicConfig( stream=sys.stdout, format="%(asctime)s - %(name)s [%(levelname)s]: %(message)s", - level=logging.DEBUG if '--debug' in sys.argv else logging.INFO + level=config.LOG_LEVEL ) + if config.SENTRY_DSN: + sentry_logging = LoggingIntegration( + level=logging.DEBUG, # Capture info and above as breadcrumbs + event_level=logging.ERROR # Send errors as events + ) + sentry_sdk.init( + dsn=config.SENTRY_DSN, + send_default_pii=True, + integrations=[sentry_logging], + traces_sample_rate=0.0, + release=config.RELEASE_ID, + environment=config.RELEASEMODE, + _experiments={"auto_enabling_integrations": True} + ) logging.info("Guard service starting...") mqtt = MQTT() mqtt.topic = config.MQTT_TOPIC mqtt.connect() mqtt.client.loop_start() # Start MQTT event loop on a different thread setup_rabbit(mqtt) + + +if __name__ == "__main__": + main() diff --git a/src/config.py b/src/config.py index d432a05..158e6d9 100644 --- a/src/config.py +++ b/src/config.py @@ -1,5 +1,7 @@ #!/usr/bin/env python3 import os +import sys +import logging """ @@ -32,3 +34,9 @@ MQTT_TOPIC = os.getenv("GUARD_MQTT_TOPIC", "guard-service") INPUT_HOSTNAME = os.getenv("INPUT_SVC_HOSTNAME", "input-service") INPUT_TIMEOUT = int(os.environ.get("INPUT_SVC_TIMEOUT", 5)) TRIGGER_LEVEL = float(os.environ.get("TRIGGER_LEVEL", 0.51)) + +LOG_LEVEL = logging.DEBUG if ( + '--debug' in sys.argv + ) or ( + os.environ.get('DEBUG', '0').lower() in ['yes', 'true', '1'] + ) else logging.INFO \ No newline at end of file