-
Notifications
You must be signed in to change notification settings - Fork 1
/
itchylog.py
47 lines (34 loc) · 1.25 KB
/
itchylog.py
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# itchylog.py
import os
import logging
import time
# Create the out folder if it doesn't exist
if not os.path.exists('out'):
os.makedirs('out')
# Create the filename with the current epoch timestamp and specify the path to the out folder
log_filename = os.path.join('out', f"scratch-{int(time.time())}.log")
# Set the debug_mode to False to disable debug logs
debug_mode = True
# # Configure logging to console
# if debug_mode:
# logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
# else:
# logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
# Configure logging to file
if debug_mode:
logging.basicConfig(filename=log_filename, level=logging.DEBUG, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
else:
logging.basicConfig(filename=log_filename, level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
# Create a logger
logger = logging.getLogger(__name__)
# Define wrapper functions for logging
def debug(msg):
logger.debug(msg)
def info(msg):
logger.info(msg)
def warning(msg):
logger.warning(msg)
def error(msg):
logger.error(msg)
def critical(msg):
logger.critical(msg)