renaming to src/neco to src/nepi
[nepi.git] / src / nepi / __init__.py
diff --git a/src/nepi/__init__.py b/src/nepi/__init__.py
new file mode 100644 (file)
index 0000000..00e54fe
--- /dev/null
@@ -0,0 +1,31 @@
+import logging
+import os
+import traceback
+
+LOGLEVEL = os.environ.get("NEPI_LOGLEVEL", "INFO").upper()
+LOGLEVEL = getattr(logging, LOGLEVEL)
+#FORMAT = "%(asctime)s %(name)-12s %(levelname)-8s %(message)s"
+FORMAT = "%(asctime)s %(name)s %(levelname)-4s %(message)s"
+
+# NEPI_LOG variable contains space separated components 
+# on which logging should be enabled
+LOG = os.environ.get("NEPI_LOG", "ALL").upper()
+
+if LOG != 'ALL':
+    # Set by default loglevel to error
+    logging.basicConfig(format = FORMAT, level = logging.ERROR)
+
+    # Set logging level to that defined by the user
+    # only for the enabled components
+    for component in LOG.split(" "):
+        try:
+           log = logging.getLogger(component)
+           log.setLevel(LOGLEVEL)
+        except:
+            err = traceback.format_exc()
+            print "ERROR ", err
+else:
+    # Set the logging level defined by the user for all
+    # components
+    logging.basicConfig(format = FORMAT, level = LOGLEVEL)
+