6
|
1 #!/usr/bin/env python
|
|
2 """
|
|
3 Set up the logging
|
|
4 """
|
|
5
|
|
6 import logging
|
|
7 import os
|
|
8
|
|
9 import ectyper.definitions as D
|
|
10
|
|
11
|
|
12 def initialize_logging():
|
|
13 """
|
|
14 Set up the screen and file logging.
|
|
15
|
|
16 Args:
|
|
17 None
|
|
18
|
|
19 Returns:
|
|
20 log_file (str): The log filename
|
|
21 """
|
|
22
|
|
23 # set up DEBUG logging to file, INFO logging to STDERR
|
|
24 log_file = os.path.join(D.WORKPLACE_DIR, 'ectyper.log')
|
|
25
|
|
26 formatter = logging.Formatter(
|
|
27 '%(asctime)s %(name)-12s %(levelname)-8s %(message)s')
|
|
28
|
|
29 # logging to file
|
|
30 logging.basicConfig(
|
|
31 level=logging.DEBUG,
|
|
32 format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s',
|
|
33 datefmt='%m-%d %H:%M',
|
|
34 filename=log_file,
|
|
35 filemode='w')
|
|
36
|
|
37 # define a Handler which writes INFO messages or higher to the sys.stderr
|
|
38 console = logging.StreamHandler()
|
|
39 console.setFormatter(formatter)
|
|
40 console.setLevel(logging.INFO)
|
|
41
|
|
42 # add the handler to the root logger
|
|
43 logging.getLogger('').addHandler(console)
|
|
44
|
|
45 return log_file
|