Spaces:
Running
Running
Create logging_config.py
Browse files
insight_and_tasks/utils/logging_config.py
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# utils/logging_config.py
|
2 |
+
import logging
|
3 |
+
import os
|
4 |
+
|
5 |
+
def setup_logging():
|
6 |
+
"""
|
7 |
+
Configures basic logging for the application.
|
8 |
+
Logs to console.
|
9 |
+
"""
|
10 |
+
log_level_str = os.environ.get("LOG_LEVEL", "INFO").upper()
|
11 |
+
log_level = getattr(logging, log_level_str, logging.INFO)
|
12 |
+
|
13 |
+
logging.basicConfig(
|
14 |
+
level=log_level,
|
15 |
+
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
|
16 |
+
datefmt="%Y-%m-%d %H:%M:%S"
|
17 |
+
)
|
18 |
+
# You can also direct logs to a file if needed:
|
19 |
+
# file_handler = logging.FileHandler("app.log")
|
20 |
+
# file_handler.setLevel(log_level)
|
21 |
+
# file_handler.setFormatter(logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s"))
|
22 |
+
# logging.getLogger().addHandler(file_handler)
|
23 |
+
|
24 |
+
# Silence overly verbose libraries if necessary
|
25 |
+
# logging.getLogger("some_verbose_library").setLevel(logging.WARNING)
|
26 |
+
|
27 |
+
logger = logging.getLogger(__name__)
|
28 |
+
logger.info(f"Logging configured with level: {log_level_str}")
|