-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger.py
51 lines (41 loc) · 1.58 KB
/
logger.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
48
49
50
#!/usr/bin/env python3
from configuration import *
import logging
from logging.handlers import RotatingFileHandler
import datetime
import sys
# writing debugging files and specific points
def log(filename,xml):
if DEBUGGING:
open(filename, 'w',encoding='utf-8').write(xml)
# writing which origin/destination was asked from NOVA
def log_entry(origin, destination, starttime,stoptime):
logger = logging.getLogger('OJP2NOVA')
# logger.setLevel(logging.INFO)
# handler = RotatingFileHandler(LOGFILE, maxBytes=80000, backupCount=10)
# logger.addHandler(handler)
tz = datetime.timezone.utc
ft = "%Y-%m-%dT%H:%M:%S%z"
t = datetime.datetime.now(tz=tz).strftime(ft)
logstr='"'+t+'";"'+origin+'";"'+destination+"';"+starttime+"';"+stoptime
logger.info(logstr)
def log_entry(logstr:str):
logger = logging.getLogger('OJP2NOVA')
logger.info(logstr)
# sets up the logger
def setup_custom_logger():
formatter = logging.Formatter(fmt='%(asctime)s %(levelname)-8s %(message)s',
datefmt='%Y-%m-%d %H:%M:%S')
handler = RotatingFileHandler(LOGFILE, maxBytes=8000000, backupCount=10)
handler.setFormatter(formatter)
screen_handler = logging.StreamHandler(stream=sys.stdout)
screen_handler.setFormatter(formatter)
logger = logging.getLogger("OJP2NOVA")
logger.setLevel(logging.INFO)
logger.addHandler(handler)
logger.addHandler(screen_handler)
return logger
# makes sure the log path exists
import pathlib
pathlib.Path("generated").mkdir(parents=True, exist_ok=True)
logger = setup_custom_logger()