Initial code push of Anteater
[releng-anteater.git] / anteater / utils / anteater_logger.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 ##############################################################################
4 # Copyright (c) 2017 jose.lausuch@ericsson.com
5 #
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Apache License, Version 2.0
8 # which accompanies this distribution, and is available at
9 # http://www.apache.org/licenses/LICENSE-2.0
10 ##############################################################################
11
12 import ConfigParser
13 import logging
14
15 config = ConfigParser.RawConfigParser()
16 config.read('anteater.conf')
17 anteater_log = config.get('config', 'anteater_log')
18
19
20 class Logger:
21     def __init__(self, logger_name):
22         self.logger = logging.getLogger(logger_name)
23         self.logger.propagate = 0
24         self.logger.setLevel(logging.DEBUG)
25
26         ch = logging.StreamHandler()
27         formatter = logging.Formatter('%(asctime)s - %(name)s - '
28                                       '%(levelname)s - %(message)s')
29         ch.setFormatter(formatter)
30         ch.setLevel(logging.DEBUG)
31         self.logger.addHandler(ch)
32
33         handler = logging.FileHandler(anteater_log)
34         handler.setFormatter(formatter)
35         handler.setLevel(logging.DEBUG)
36         self.logger.addHandler(handler)
37
38     def getLogger(self):
39         return self.logger