-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.py
49 lines (40 loc) · 1.39 KB
/
main.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
#!/usr/bin/env python
import sys
import logging
import logging.config
import solution
def get_log_level(log_args):
# Numeric levels 10, 20, 30, 40
valid_levels = ['DEBUG', 'INFO', 'WARNING', 'ERROR']
proposed_level = log_args[0].split("=", 1)[1].upper()
if not proposed_level in valid_levels:
raise ValueError('Invalid log level: %s' % proposed_level)
return proposed_level
def main():
"""
Note: Manually override the lowest-severity log message level
that the logger will handle from the command line by executing with flags:
i.e. python main.py --log=WARNING
Sample usage:
logger.debug('debug message')
logger.info('info message')
logger.warning('warn message')
logger.error('error message')
"""
# Load logger config
logging.config.fileConfig('logging.conf')
# Create logger
logger = logging.getLogger('Recogniser logger')
# Specify lowest-severity log message a logger will handle
logger.setLevel('ERROR')
if len(sys.argv):
log_args = [arg for arg in sys.argv if '--log=' in arg]
if len(log_args) > 0:
logger.setLevel(get_log_level(log_args))
# Get current logging level
numeric_level = logging.getLogger().getEffectiveLevel()
logging.info('Starting Recogniser')
solution.run()
logging.info('Finished Recogniser')
if __name__ == '__main__':
main()