Spaces:
Sleeping
Sleeping
Ezhil
commited on
Commit
·
68062ea
1
Parent(s):
83ca740
changes
Browse files
logger.py
CHANGED
|
@@ -1,33 +1,24 @@
|
|
| 1 |
-
# import logging
|
| 2 |
-
# import os
|
| 3 |
-
|
| 4 |
-
# # Create logs directory if it doesn't exist
|
| 5 |
-
# if not os.path.exists("logs"):
|
| 6 |
-
# os.makedirs("logs")
|
| 7 |
-
|
| 8 |
-
# # Configure logging
|
| 9 |
-
# logging.basicConfig(
|
| 10 |
-
# level=logging.INFO,
|
| 11 |
-
# format="%(asctime)s - %(levelname)s - %(message)s",
|
| 12 |
-
# handlers=[
|
| 13 |
-
# logging.FileHandler("logs/app.log"), # Log to file
|
| 14 |
-
# logging.StreamHandler() # Log to console
|
| 15 |
-
# ],
|
| 16 |
-
# )
|
| 17 |
-
|
| 18 |
-
# # Get logger instance
|
| 19 |
-
# logger = logging.getLogger("world_population")
|
| 20 |
-
|
| 21 |
-
|
| 22 |
import logging
|
| 23 |
import os
|
| 24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
# Ensure the logs directory exists
|
| 26 |
-
os.makedirs(
|
| 27 |
|
| 28 |
-
# Configure logging
|
| 29 |
logging.basicConfig(
|
| 30 |
-
|
| 31 |
level=logging.INFO,
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
| 33 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import logging
|
| 2 |
import os
|
| 3 |
|
| 4 |
+
# Define absolute path for logs
|
| 5 |
+
LOG_DIR = "/app/logs"
|
| 6 |
+
LOG_FILE = os.path.join(LOG_DIR, "backend.log")
|
| 7 |
+
|
| 8 |
# Ensure the logs directory exists
|
| 9 |
+
os.makedirs(LOG_DIR, exist_ok=True)
|
| 10 |
|
| 11 |
+
# Configure logging settings
|
| 12 |
logging.basicConfig(
|
| 13 |
+
format="%(asctime)s - %(levelname)s - %(message)s",
|
| 14 |
level=logging.INFO,
|
| 15 |
+
handlers=[
|
| 16 |
+
logging.FileHandler(LOG_FILE), # Use absolute path
|
| 17 |
+
logging.StreamHandler() # Print logs to the console
|
| 18 |
+
]
|
| 19 |
)
|
| 20 |
+
|
| 21 |
+
logger = logging.getLogger(__name__)
|
| 22 |
+
|
| 23 |
+
if __name__ == "__main__":
|
| 24 |
+
logger.info("Logger is set up correctly!")
|