annotate ecoli_serotyping/loggingFunctions.py @ 6:fe3ceb5c4214 draft

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