Statistiques
| Branche: | Tag: | Révision :

dockonsurf / modules / config_log.py @ 07bba5bb

Historique | Voir | Annoter | Télécharger (1,02 ko)

1
"""Configures the logger to record all calculation events on a log file."""
2
import sys
3
import logging
4

    
5

    
6
def log_exception(exc_type, exc_value, exc_tb):
7
    if issubclass(exc_type, KeyboardInterrupt):
8
        sys.__excepthook__(exc_type, exc_value, exc_tb)
9
        return
10
    logger = logging.getLogger('DockOnSurf')
11
    logger.error("", exc_info=(exc_type, exc_value, exc_tb))
12

    
13

    
14
def config_log(label):  # TODO Format log to break line after column 80.
15
    logging.captureWarnings(True)
16
    warnings_logger = logging.getLogger("py.warnings")
17

    
18
    logger = logging.getLogger(label)
19
    logger.setLevel(logging.INFO)
20

    
21
    log_handler = logging.FileHandler('dockonsurf.log', mode='w')
22
    log_handler.setLevel(logging.INFO)
23
    log_format = logging.Formatter(fmt='%(asctime)s-%(levelname)s: %(message)s',
24
                                   datefmt='%d-%b-%y %H:%M:%S')
25
    log_handler.setFormatter(log_format)
26

    
27
    logger.addHandler(log_handler)
28
    warnings_logger.addHandler(log_handler)
29
    sys.excepthook = log_exception
30

    
31
    return logger