-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmy_logger.py
More file actions
53 lines (37 loc) · 1.27 KB
/
my_logger.py
File metadata and controls
53 lines (37 loc) · 1.27 KB
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
48
49
50
51
52
53
"""
This module handles the logging for dcc_xml generator
"""
import logging
from logging.handlers import TimedRotatingFileHandler
import re
from datetime import datetime
g_logger = None
def init():
log_file = '/projects/galaxy/tools/cba/log/aws_log'
global g_logger
g_logger = logging.getLogger(__name__)
date = datetime.now().strftime("%B-%d-%Y")
#FORMAT = "[%(asctime)s->%(filename)s->%(funcName)s():%(lineno)s]%(levelname)s: %(message)s"
FORMAT = "[%(asctime)s]%(levelname)s: %(message)s"
logging.basicConfig(format=FORMAT, filemode="w", level=logging.DEBUG, force=True)
handler =TimedRotatingFileHandler(f"{log_file}_{date}.log" , when="midnight", backupCount=10)
handler.setFormatter(logging.Formatter(FORMAT))
handler.suffix = "%Y%m%d"
handler.extMatch = re.compile(r"^\d{8}$")
g_logger.addHandler(handler)
g_logger.info('Logger has been created')
def info(message):
global g_logger
if g_logger == None:
init()
g_logger.info(message)
def debug(message):
global g_logger
if g_logger == None:
init()
g_logger.debug(message)
def error(message):
global g_logger
if g_logger == None:
init()
g_logger.error(message)