forked from astropy/astroquery
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogger.py
More file actions
36 lines (29 loc) · 1.1 KB
/
logger.py
File metadata and controls
36 lines (29 loc) · 1.1 KB
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
import logging
from astropy.logger import AstropyLogger
def _init_log(config=None):
"""
Initializes the logger, using the AstropyLogger class.
"""
orig_logger_cls = logging.getLoggerClass()
logging.setLoggerClass(AstropyLogger)
try:
log = logging.getLogger('astroquery')
if config is not None:
_config_to_loggerConf(config)
log._set_defaults()
finally:
logging.setLoggerClass(orig_logger_cls)
return log
def _config_to_loggerConf(config):
"""
Translates a user-provided config to `~astropy.logger.LoggerConf`.
"""
if config.has_section('logger'):
from astropy.logger import Conf as LoggerConf
conf = LoggerConf()
loggerconf_option_list = ['log_level', 'use_color', 'log_warnings', 'log_exceptions', 'log_to_file',
'log_file_path', 'log_file_level', 'log_file_format']
for this_option in loggerconf_option_list:
if config.has_option('logger', this_option):
setattr(conf, this_option, config.get('logger', this_option))
return conf