-
Notifications
You must be signed in to change notification settings - Fork 0
/
appconf.py
84 lines (77 loc) · 2.16 KB
/
appconf.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import os
import logging
import datetime
import calendar
# Name of application file without extension
APPFILE_NAME = 'cron1min'
# Name of log files
LOGFILE_NAME = APPFILE_NAME + '.info'
DEBUGFILE_NAME = APPFILE_NAME + '.dbug'
# Logging handler level
CONSOLE_LEVEL = 'INFO'
FILE_LEVEL = 'INFO'
DEBUG_LEVEL = 'DEBUG'
# Do not make changes in this section
THIS_PATH = os.path.abspath(__file__)
THIS_DIR = os.path.split(THIS_PATH)[0]
LOGFILE_PATH = THIS_DIR + '/' + LOGFILE_NAME
DEBUGFILE_PATH = THIS_DIR + '/' + DEBUGFILE_NAME
# Specify logging filter
class DayFilter(logging.Filter):
""" Inserts day of week into log entries. """
def filter(self, record):
day_int = datetime.datetime.today().weekday()
dayofweek = calendar.day_abbr[day_int]
record.dayofweek = dayofweek
return True
# logging configuration dictionary
LOG_CONFIG = {
'version': 1,
'disable_existing_loggers': False,
'filters': {
'dayfilter': {
'()': DayFilter,
},
},
'root': {
'level': 'NOTSET',
'handlers': [
'console',
'file',
# 'debug'
]
},
'loggers': {
},
'formatters': {
'datetimeday': {
'format': '%(asctime)-15s %(levelname)-7s %(dayofweek)s %(message)s',
'datefmt': '%Y-%m-%d %H:%M:%S',
},
},
'handlers': {
'console': {
'level': CONSOLE_LEVEL,
'filters': ['dayfilter'],
'formatter': 'datetimeday',
'stream': 'ext://sys.stdout',
'class': 'logging.StreamHandler',
},
'file': {
'level': FILE_LEVEL,
'filters': ['dayfilter'],
'formatter': 'datetimeday',
'mode': 'a', # append mode
'filename': LOGFILE_PATH,
'class': 'logging.FileHandler', # file does not rotate
},
'debug': {
'level': DEBUG_LEVEL,
'filters': ['dayfilter'],
'formatter': 'datetimeday',
'mode': 'a', # append mode
'filename': DEBUGFILE_PATH,
'class': 'logging.FileHandler', # file does not rotate
},
},
}