use additional loki logger #48

Merged
remoll merged 6 commits from feature/backend/centralized-logging into main 2025-01-08 09:43:38 +00:00
3 changed files with 11 additions and 6 deletions
Showing only changes of commit c448e2dfb7 - Show all commits

View File

@ -1,3 +0,0 @@
{
"cmake.ignoreCMakeListsMissing": true
}

@ -1 +1 @@
Subproject commit 4f0a0289fcf8a7755d7dc1a76b443fe1233685ae Subproject commit 904f16bfc0624b6ab8569e0a70050aaa3bd64b3f

View File

@ -21,11 +21,19 @@ debug = os.getenv('DEBUG', "false") == "true"
if os.getenv('KUBERNETES_SERVICE_HOST', None) is not None: if os.getenv('KUBERNETES_SERVICE_HOST', None) is not None:
# in that case we want to log to stdout and also to loki # in that case we want to log to stdout and also to loki
from loki_logger_handler.loki_logger_handler import LokiLoggerHandler from loki_logger_handler.loki_logger_handler import LokiLoggerHandler
loki_url = os.getenv('LOKI_URL')
if loki_url is None:
raise ValueError("LOKI_URL environment variable is not set")
loki_handler = LokiLoggerHandler( loki_handler = LokiLoggerHandler(
url=os.getenv('LOKI_URL', 'http://loki:3100'), url = loki_url,
labels={'app': 'anyway', 'env': 'production' if debug else 'staging'} labels = {'app': 'anyway', 'environment': 'production' if debug else 'staging'}
) )
print(f"Logging to Loki at {loki_url} with {loki_handler.labels} and {debug=}")
if debug: if debug:
# we need to silence the debug logs made by the loki handler
logging.getLogger('urllib3.connectionpool').setLevel(logging.INFO)
logging.basicConfig( logging.basicConfig(
level=logging.DEBUG, level=logging.DEBUG,
handlers=[loki_handler, logging.StreamHandler()] handlers=[loki_handler, logging.StreamHandler()]