20a4125422187b1d8b92b4dd48c53579e46a48d3
[nepi.git] / src / nepi / util / logger.py
1 """
2     NEPI, a framework to manage network experiments
3     Copyright (C) 2013 INRIA
4
5     This program is free software: you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation, either version 3 of the License, or
8     (at your option) any later version.
9
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14
15     You should have received a copy of the GNU General Public License
16     along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
18 """
19
20 import logging
21
22
23 class Logger(object):
24     def __init__(self, logger_component):
25         self._logger = logging.getLogger(logger_component)
26
27     def debug(self, msg, out = None, err = None):
28         self.log(msg, logging.DEBUG, out, err)
29
30     def error(self, msg, out = None, err = None):
31         self.log(msg, logging.ERROR, out, err)
32
33     def warn(self, msg, out = None, err = None):
34         self.log(msg, logging.WARNING, out, err)
35
36     def info(self, msg, out = None, err = None):
37         self.log(msg, logging.INFO, out, err)
38
39     def log(self, msg, level, out = None, err = None):
40         if out:
41             msg += " - OUT: %s " % out
42
43         if err:
44             msg += " - ERROR: %s " % err
45
46         msg = self.log_message(msg)
47
48         self.logger.log(level, msg)
49
50     def log_message(self, msg):
51         return msg
52
53     @property
54     def logger(self):
55         return self._logger