Adding authors and correcting licence information
[nepi.git] / src / nepi / __init__.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 # Author: Alina Quereilhac <alina.quereilhac@inria.fr>
19
20 import logging
21 import os
22 import traceback
23
24 LOGLEVEL = os.environ.get("NEPI_LOGLEVEL", "INFO").upper()
25 LOGLEVEL = getattr(logging, LOGLEVEL)
26 #FORMAT = "%(asctime)s %(name)-12s %(levelname)-8s %(message)s"
27 FORMAT = "%(asctime)s %(name)s %(levelname)-4s %(message)s"
28
29 # NEPI_LOG variable contains space separated components 
30 # on which logging should be enabled
31 LOG = os.environ.get("NEPI_LOG", "ALL").upper()
32
33 if LOG != 'ALL':
34     # Set by default loglevel to error
35     logging.basicConfig(format = FORMAT, level = logging.ERROR)
36
37     # Set logging level to that defined by the user
38     # only for the enabled components
39     for component in LOG.split(" "):
40         try:
41            log = logging.getLogger(component)
42            log.setLevel(LOGLEVEL)
43         except:
44             err = traceback.format_exc()
45             print "ERROR ", err
46 else:
47     # Set the logging level defined by the user for all
48     # components
49     logging.basicConfig(format = FORMAT, level = LOGLEVEL)
50