1
2 """Configure logging for edPDB analysis.
3
4 Import this module if logging is desired in application code.
5 """
6
7 import logging
8
9 -def create(logfile='edPDB.log'):
10 """Create a top level logger.
11
12 - The file logger logs everything (including DEBUG).
13 - The console logger only logs INFO and above.
14
15 Logging to a file and the console.
16
17 See http://docs.python.org/library/logging.html?#logging-to-multiple-destinations
18
19 The top level logger of the library is named 'edPDB'. Note that
20 we are configuring this logger with console output. If the root
21 logger also does this then we will get two output lines to the
22 console. We'll live with this because this is a simple
23 convenience library...
24 """
25
26 logger = logging.getLogger('edPDB')
27
28 logger.setLevel(logging.DEBUG)
29
30 logfile = logging.FileHandler(logfile)
31 logfile_formatter = logging.Formatter('%(asctime)s %(name)-12s %(levelname)-8s %(message)s')
32 logfile.setFormatter(logfile_formatter)
33 logger.addHandler(logfile)
34
35
36 console = logging.StreamHandler()
37 console.setLevel(logging.INFO)
38
39 formatter = logging.Formatter('%(name)-12s: %(levelname)-8s %(message)s')
40 console.setFormatter(formatter)
41
42 logger.addHandler(console)
43
44 return logger
45
47 """clean out handlers in the library top level logger
48
49 (only important for reload/debug cycles...)
50 """
51 for h in logger.handlers:
52 logger.removeHandler(h)
53