Merge neco to nepi-3.0
[nepi.git] / src / nepi / __init__.py
1 import logging
2 import os
3 import traceback
4
5 LOGLEVEL = os.environ.get("NEPI_LOGLEVEL", "INFO").upper()
6 LOGLEVEL = getattr(logging, LOGLEVEL)
7 #FORMAT = "%(asctime)s %(name)-12s %(levelname)-8s %(message)s"
8 FORMAT = "%(asctime)s %(name)s %(levelname)-4s %(message)s"
9
10 # NEPI_LOG variable contains space separated components 
11 # on which logging should be enabled
12 LOG = os.environ.get("NEPI_LOG", "ALL").upper()
13
14 if LOG != 'ALL':
15     # Set by default loglevel to error
16     logging.basicConfig(format = FORMAT, level = logging.ERROR)
17
18     # Set logging level to that defined by the user
19     # only for the enabled components
20     for component in LOG.split(" "):
21         try:
22            log = logging.getLogger(component)
23            log.setLevel(LOGLEVEL)
24         except:
25             err = traceback.format_exc()
26             print "ERROR ", err
27 else:
28     # Set the logging level defined by the user for all
29     # components
30     logging.basicConfig(format = FORMAT, level = LOGLEVEL)
31