File size: 757 Bytes
a244ac5
 
 
 
 
 
fccc80a
a244ac5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import logging

import os
from datetime import datetime

# Create a timestamped log directory and file
LOG_DIR = os.path.join("/tmp", "logs")
os.makedirs(LOG_DIR, exist_ok=True)
LOG_FILE = f"log_{datetime.now().strftime('%Y-%m-%d_%H-%M-%S')}.log"
LOG_FILE_PATH = os.path.join(LOG_DIR, LOG_FILE)

# Configure more readable, structured logging
logging.basicConfig(
    filename=LOG_FILE_PATH,
    format=(
        "\n-----------------------------\n"
        "Time       : %(asctime)s\n"
        "Level      : %(levelname)s\n"
        "Module     : %(name)s\n"
        "Line       : %(lineno)d\n"
        "Message    : %(message)s\n"
        "-----------------------------\n"
    ),
    level=logging.INFO,
    datefmt="%Y-%m-%d %H:%M:%S"
)

# Example usage