aboutsummaryrefslogtreecommitdiff
blob: a90f578604fd55f9ca1cbfb1b7e34c9af2ade476 (plain)
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
import os
from errno import *
import logging as log
import config

fhandler = None

def init_logging(dir):
    """Initialize logging file and settings
    """
    global fhandler
    try:
        os.mkdir(dir)
    except OSError, e:
        if e.errno != EEXIST:
            raise e

    if fhandler is not None:
        fhandler.close()
        log.getLogger('').removeHandler(fhandler)
    fhandler = log.FileHandler(dir+"/tinderbox.log")
    formatter = log.Formatter('%(asctime)s %(levelname)s %(message)s')
    fhandler.setFormatter(formatter)
    log.getLogger('').addHandler(fhandler)
    fhandler.setLevel(config.LOG_LEVEL)