c307144c99ce2aa4a4bcda23bed3da3334abe326
[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)s %(levelname)-4s %(message)s"
27
28 # NEPI_LOG variable contains space separated components 
29 # on which logging should be enabled
30 LOG = os.environ.get("NEPI_LOG", "ALL").upper()
31
32 if LOG != 'ALL':
33     # Set by default loglevel to error
34     logging.basicConfig(format = FORMAT, level = logging.ERROR)
35
36     # Set logging level to that defined by the user
37     # only for the enabled components
38     for component in LOG.split(" "):
39         try:
40            log = logging.getLogger(component)
41            log.setLevel(LOGLEVEL)
42         except:
43             err = traceback.format_exc()
44             print "ERROR ", err
45 else:
46     # Set the logging level defined by the user for all
47     # components
48     logging.basicConfig(format = FORMAT, level = LOGLEVEL)
49
50
51 # Add RMs to ResourceFactory. Use NEPI_SEARCH_PATH to 
52 # override the default path to search for RMs
53 from nepi.execution.resource import populate_factory
54 populate_factory()
55
56