bb2f1729586e8532fff8b912de21ae0865a57172
[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 version 2 as
7 #    published by the Free Software Foundation;
8 #
9 #    This program is distributed in the hope that it will be useful,
10 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
11 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 #    GNU General Public License for more details.
13 #
14 #    You should have received a copy of the GNU General Public License
15 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 #
17 # Author: Alina Quereilhac <alina.quereilhac@inria.fr>
18
19 import logging
20 import os
21 import traceback
22
23 LOGLEVEL = os.environ.get("NEPI_LOGLEVEL", "INFO").upper()
24 LOGLEVEL = getattr(logging, LOGLEVEL)
25 FORMAT = "%(asctime)s %(name)s %(levelname)-4s %(message)s"
26
27 # NEPI_LOG variable contains space separated components 
28 # on which logging should be enabled
29 LOG = os.environ.get("NEPI_LOG", "ALL").upper()
30
31 if LOG != 'ALL':
32     # Set by default loglevel to error
33     logging.basicConfig(format = FORMAT, level = logging.ERROR)
34
35     # Set logging level to that defined by the user
36     # only for the enabled components
37     for component in LOG.split(" "):
38         try:
39            log = logging.getLogger(component)
40            log.setLevel(LOGLEVEL)
41         except:
42             err = traceback.format_exc()
43             print "ERROR ", err
44 else:
45     # Set the logging level defined by the user for all
46     # components
47     logging.basicConfig(format = FORMAT, level = LOGLEVEL)
48
49
50 # Add RMs to ResourceFactory. Use NEPI_SEARCH_PATH to 
51 # override the default path to search for RMs
52 from nepi.execution.resource import populate_factory
53 populate_factory()
54
55