Subversion Repositories basico

Rev

Rev 171 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
4 t00mlabs 1
#!/usr/bin/python
2
# -*- coding: utf-8 -*-
3
# File: log.py
4
# Author: Tomás Vírseda
5
# License: GPL v3
6
# Description: log service
7
 
8
from os.path import sep as SEP
9
import logging
171 t00m 10
import inspect
4 t00mlabs 11
 
12
def get_logger(name, LOG_FILE):
13
    """Returns a new logger with personalized.
14
    @param name: logger name
15
    """
16
    log = logging.getLogger(name)
17
    log.setLevel(logging.DEBUG)
18
 
19
    ## Redirect log to stdout
141 t00mlabs 20
    formatter = logging.Formatter("%(levelname)7s | %(asctime)s | %(message)s")
150 t00m 21
    # ~ formatter = logging.Formatter("%(levelname)7s | %(lineno)4d  |%(name)15s | %(asctime)s | %(message)s")
4 t00mlabs 22
    ch = logging.StreamHandler()    # Create console handler and set level to debug
23
    ch.setLevel(logging.DEBUG)      # Set logging devel
24
    ch.setFormatter(formatter)      # add formatter to console handler
25
    log.addHandler(ch)              # add console handler to logger
26
 
133 t00mlabs 27
    #FIXME Redirect log to file
134 t00mlabs 28
    fh = logging.FileHandler(LOG_FILE)
29
    fh.setFormatter(formatter)
30
    fh.setLevel(logging.DEBUG)      # Set logging devel
31
    log.addHandler(fh)              # add file handler to logger
4 t00mlabs 32
 
33
    return log