Adding __version__ to nepi
[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 __version__ = "3.0"
25
26 LOGLEVEL = os.environ.get("NEPI_LOGLEVEL", "INFO").upper()
27 LOGLEVEL = getattr(logging, LOGLEVEL)
28 FORMAT = "%(asctime)s %(name)s %(levelname)-4s %(message)s"
29
30 # NEPI_LOG variable contains space separated components 
31 # on which logging should be enabled
32 LOG = os.environ.get("NEPI_LOG", "ALL").upper()
33
34 if LOG != 'ALL':
35     # Set by default loglevel to error
36     logging.basicConfig(format = FORMAT, level = logging.ERROR)
37
38     # Set logging level to that defined by the user
39     # only for the enabled components
40     for component in LOG.split(" "):
41         try:
42            log = logging.getLogger(component)
43            log.setLevel(LOGLEVEL)
44         except:
45             err = traceback.format_exc()
46             print "ERROR ", err
47 else:
48     # Set the logging level defined by the user for all
49     # components
50     logging.basicConfig(format = FORMAT, level = LOGLEVEL)
51