Download src/telemetry/logging_utils.py from RAGnTeX/ragntex: direct link, hf CLI and curl.
- Browser
- Download file 1.32 kB
-
https://huggingface.co/spaces/RAGnTeX/ragntex/resolve/main/src/telemetry/logging_utils.py
- Command line
-
hf download hf://spaces/RAGnTeX/ragntex/src/telemetry/logging_utils.py
-
curl -L -o logging_utils.py https://huggingface.co/spaces/RAGnTeX/ragntex/resolve/main/src/telemetry/logging_utils.py
1.32 kB
| """Module for setting up and managing a global logger instance.""" | |
| import logging | |
| class Logger: | |
| """ | |
| Class containing the global logger instance. | |
| """ | |
| _logger = None | |
| def setup_logging(cls) -> None: | |
| """ | |
| Configure logging for the project. | |
| """ | |
| if cls._logger is None: | |
| logging.basicConfig( | |
| format="[%(asctime)s][%(levelname)s][%(funcName)s] %(message)s", | |
| level=logging.INFO, # Set the desired log level here | |
| datefmt="%Y-%m-%d %H:%M:%S", | |
| ) | |
| cls._logger = logging.getLogger("Logger") | |
| # add compatibility with opentelemetry | |
| otel_loggers = [ | |
| "opentelemetry.sdk", | |
| "opentelemetry.trace", | |
| "opentelemetry.exporter.otlp.proto.http.trace_exporter", | |
| ] | |
| for name in otel_loggers: | |
| logging.getLogger(name).setLevel(logging.DEBUG) | |
| def get_logger(cls) -> logging.Logger: | |
| """ | |
| Returns the global logger instance. | |
| """ | |
| cls.setup_logging() # Ensure logging is set up before returning the logger | |
| if cls._logger is None: | |
| raise RuntimeError("Logger was not properly initialized") | |
| return cls._logger | |