Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions app/apilogger.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""Logging utilities for the IRI Facility API."""
import logging

LEVELS = {"FATAL": logging.FATAL,
"ERROR": logging.ERROR,
"WARNING": logging.WARNING,
"INFO": logging.INFO,
"DEBUG": logging.DEBUG}


def get_stream_logger(name: str = __name__, level: str = "DEBUG") -> logging.Logger:
"""
Return a configured Stream logger.
"""
logger = logging.getLogger(name)

if not logger.handlers:
handler = logging.StreamHandler()

formatter = logging.Formatter("%(asctime)s.%(msecs)03d - %(name)s - %(levelname)s - %(message)s", datefmt="%a, %d %b %Y %H:%M:%S")

handler.setFormatter(formatter)
logger.addHandler(handler)

logger.setLevel(LEVELS.get(level, logging.DEBUG))
logger.propagate = False

return logger
25 changes: 21 additions & 4 deletions app/config.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
"""Configuration for the IRI Facility API reference implementation."""
import os
import logging
import json
from .apilogger import get_stream_logger

logging.basicConfig()
logging.getLogger().setLevel(logging.INFO)
LOG_LEVEL = os.environ.get("LOG_LEVEL", "DEBUG")

logger = get_stream_logger(__name__, LOG_LEVEL)

API_VERSION = "1.0.0"

Expand Down Expand Up @@ -31,7 +33,7 @@
d2 = json.loads(os.environ.get("IRI_API_PARAMS", "{}"))
API_CONFIG.update(d2)
except Exception as exc:
logging.getLogger().error(f"Error parsing IRI_API_PARAMS: {exc}")
logger.error(f"Error parsing IRI_API_PARAMS: {exc}")


API_URL_ROOT = os.environ.get("API_URL_ROOT", "https://api.iri.nersc.gov")
Expand All @@ -42,3 +44,18 @@
OPENTELEMETRY_DEBUG = os.environ.get("OPENTELEMETRY_DEBUG", "false").lower() == "true"
OTLP_ENDPOINT = os.environ.get("OTLP_ENDPOINT", "")
OTEL_SAMPLE_RATE = float(os.environ.get("OTEL_SAMPLE_RATE", "0.2"))

# Print all startup config for debugging
logger.info("IRI Facility API starting with config:")
logger.info("="*40)
logger.info(f"API_VERSION={API_VERSION}")
logger.info(f"API_CONFIG={API_CONFIG}")
logger.info(f"API_URL_ROOT={API_URL_ROOT}")
logger.info(f"API_PREFIX={API_PREFIX}")
logger.info(f"API_URL={API_URL}")
logger.info(f"LOG_LEVEL={LOG_LEVEL}")
logger.info(f"OPENTELEMETRY_ENABLED={OPENTELEMETRY_ENABLED}")
logger.info(f"OPENTELEMETRY_DEBUG={OPENTELEMETRY_DEBUG}")
logger.info(f"OTLP_ENDPOINT={OTLP_ENDPOINT}")
logger.info(f"OTEL_SAMPLE_RATE={OTEL_SAMPLE_RATE}")
logger.info("="*40)
Loading