-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcode_snippet_dump.py
45 lines (36 loc) · 1.3 KB
/
code_snippet_dump.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
def create_logger(logging_mode):
"""
Manage logging behavior
Notes
-----------
See https://docs.python.org/3/howto/logging.html#logging-basic-tutorial
"""
if logging_mode.lower() == 'installation':
## Provide most detailed infos to stdout
# logger_name = 'install'
log_level = logging.DEBUG
# create console handler
elif logging_mode.lower() == 'operation':
## Provide only warning level output to log-file
# logger_name = 'operate'
log_level = logging.INFO
# Create file handler
#ch = logging.FileHandler(eia_tmp_path + 'EidaAvailability.log')
#print("Find log file at %s" % eia_tmp_path + 'EidaAvailability.log')
else:
raise RuntimeError("Logging mode unspecified. Choose" +
"'installation' or 'operation'.")
# create logger
logger = logging.getLogger('eida_availability')
logger.setLevel(logging.DEBUG)
# console handler
console = logging.StreamHandler()
# set level
console.setLevel(log_level)
# create formatter
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
# add formatter to ch
console.setFormatter(formatter)
# add ch to logger
logger.addHandler(console)
return logger