v0.4.52 fixes logging name mismatching. Add individual log files per module
authortierno <alfonso.tiernosepulveda@telefonica.com>
Mon, 12 Sep 2016 16:11:11 +0000 (18:11 +0200)
committertierno <alfonso.tiernosepulveda@telefonica.com>
Mon, 12 Sep 2016 16:11:11 +0000 (18:11 +0200)
Change-Id: I15c922fb2e6135662e2d12e2898e790be9fb3602
Signed-off-by: tierno <alfonso.tiernosepulveda@telefonica.com>
httpserver.py
nfvo.py
openmano_schemas.py
openmanod.cfg
openmanod.py
vimconn.py
vimconn_openstack.py
vimconn_openvim.py
vimconn_vmware.py

index 83ed06f..a4e7fb9 100644 (file)
@@ -52,6 +52,7 @@ global mydb
 global url_base
 global logger
 url_base="/openmano"
+logger = None
 
 HTTP_Bad_Request =          400
 HTTP_Unauthorized =         401 
@@ -112,7 +113,8 @@ class httpserver(threading.Thread):
         global mydb
         global logger
         #initialization
-        logger = logging.getLogger('openmano.http')
+        if not logger:
+            logger = logging.getLogger('openmano.http')
         threading.Thread.__init__(self)
         self.host = host
         self.port = port   #Port where the listen service must be started
diff --git a/nfvo.py b/nfvo.py
index 7dbd51d..da2cfa0 100644 (file)
--- a/nfvo.py
+++ b/nfvo.py
@@ -41,10 +41,11 @@ from db_base import db_base_Exception
 
 global global_config
 global vimconn_imported
+global logger
 
 
 vimconn_imported={} #dictionary with VIM type as key, loaded module as value
-logger = logging.getLogger('mano.nfvo')
+logger = logging.getLogger('openmano.nfvo')
 
 class NfvoException(Exception):
     def __init__(self, message, http_code):
index 3d95dc7..8af4682 100644 (file)
@@ -102,8 +102,13 @@ config_schema = {
         "log_level": log_level_schema,
         "log_socket_level": log_level_schema,
         "log_level_db": log_level_schema,
-        "log_level_vimconn": log_level_schema,
+        "log_level_vim": log_level_schema,
         "log_level_nfvo": log_level_schema,
+        "log_level_http": log_level_schema,
+        "log_file_db": path_schema,
+        "log_file_vim": path_schema,
+        "log_file_nfvo": path_schema,
+        "log_file_http": path_schema,
         "log_socket_host": nameshort_schema,
         "log_socket_port": port_schema,
         "log_file": path_schema,
index e4dc4e1..0540e1b 100644 (file)
@@ -54,12 +54,19 @@ db_name:   mano_db            # Name of the MANO DB
 #logging parameters for internal file stororage
    #choose among: DEBUG, INFO, WARNING, ERROR, CRITICAL
 log_level:         DEBUG  #general log levels for internal logging      
-log_level_db:      DEBUG  #database log levels
-log_level_vimconn: DEBUG  #VIM connection log levels
-log_level_nfvo:    DEBUG  #Main engine log levels
 #standard output is used unless 'log_file' is specify 
 #log_file:          /var/log/openmano/openmano.log
 
+#individual loggin settings
+#log_level_db:      DEBUG  #database log levels
+#log_file_db:       /var/log/openmano/openmano_db.log
+#log_level_vim:     DEBUG  #VIM connection log levels
+#log_file_vim:      /var/log/openmano/openmano_vimconn.log
+#log_level_nfvo:    DEBUG  #Main engine log levels
+#log_file_nfvo:      /var/log/openmano/openmano_nfvo.log
+#log_level_http:    DEBUG  #Main engine log levels
+#log_file_http:      /var/log/openmano/openmano_http.log
+
 #Uncomment to send logs via IP to an external host
 #log_socket_host:   localhost
 log_socket_port:   9022
index 69e6755..5294a9f 100755 (executable)
@@ -33,7 +33,7 @@ It loads the configuration file and launches the http_server thread that will li
 '''
 __author__="Alfonso Tierno, Gerardo Garcia, Pablo Montes"
 __date__ ="$26-aug-2014 11:09:29$"
-__version__="0.4.51-r493"
+__version__="0.4.52-r494"
 version_date="Sep 2016"
 database_version="0.13"      #expected database schema version
 
@@ -125,9 +125,9 @@ def usage():
     print( "      -p|--port [port_number]: changes port number and overrides the port number in the configuration file (default: 9090)")
     print( "      -P|--adminport [port_number]: changes admin port number and overrides the port number in the configuration file (default: 9095)")
     #print( "      -V|--vnf-repository: changes the path of the vnf-repository and overrides the path in the configuration file")
-    print( "      --log-socket-host: send logs to this host")
-    print( "      --log-socket-port: send logs using this port (default: 9022)")
-    print( "      --log-file: send logs to this file")
+    print( "      --log-socket-host HOST: send logs to this host")
+    print( "      --log-socket-port PORT: send logs using this port (default: 9022)")
+    print( "      --log-file FILE: send logs to this file")
     return
     
 if __name__=="__main__":
@@ -149,7 +149,7 @@ if __name__=="__main__":
     # Read parameters and configuration file 
     try:
         #load parameters and configuration
-        opts, args = getopt.getopt(sys.argv[1:], "hvc:V:p:P:", ["config", "help", "version", "port", "vnf-repository", "adminport", "log-socket-host=", "log-socket-port=", "log-file="])
+        opts, args = getopt.getopt(sys.argv[1:], "hvc:V:p:P:", ["config=", "help", "version", "port=", "vnf-repository=", "adminport=", "log-socket-host=", "log-socket-port=", "log-file="])
         port=None
         port_admin = None
         config_file = 'openmanod.cfg'
@@ -241,6 +241,23 @@ if __name__=="__main__":
         logger.setLevel(getattr(logging, global_config['log_level']))
         logger.critical("Starting openmano server command: '%s'", sys.argv[0])
         
+        for log_module in ("nfvo", "http", "vim", "db"):
+            log_level_module = "log_level_" + log_module
+            log_file_module = "log_file_" + log_module
+            logger_module = logging.getLogger('openmano.' + log_module)
+            if log_level_module in global_config:
+                logger_module.setLevel(global_config[log_level_module])
+            if log_file_module in global_config:
+                try:
+                    file_handler= logging.handlers.RotatingFileHandler(global_config[log_file_module], maxBytes=100e6, backupCount=9, delay=0)
+                    file_handler.setFormatter(log_formatter_simple)
+                    logger_module.addHandler(file_handler)
+                except IOError as e:
+                    raise LoadConfigurationException("Cannot open logging file '{}': {}. Check folder exist and permissions".format(global_config[log_file_module], str(e)) ) 
+            global_config["logger_"+log_module] = logger_module
+        #httpserver.logger = global_config["logger_http"]
+        #nfvo.logger = global_config["logger_nfvo"]
+        
         # Initialize DB connection
         mydb = nfvo_db.nfvo_db(log_level=global_config["log_level_db"]);
         if mydb.connect(global_config['db_host'], global_config['db_user'], global_config['db_passwd'], global_config['db_name']) == -1:
index 7e82590..e6e0421 100644 (file)
@@ -92,7 +92,7 @@ class vimconnector():
         self.user      = user
         self.passwd    = passwd
         self.config    = config
-        self.logger = logging.getLogger('mano.vim')
+        self.logger = logging.getLogger('openmano.vim')
         self.logger.setLevel( getattr(logging, log_level) )
         if not self.url_admin:  #try to use normal url 
             self.url_admin = self.url
index 314027d..80f47f5 100644 (file)
@@ -82,7 +82,7 @@ class vimconnector(vimconn.vimconnector):
             self.k_creds['password'] = passwd
             self.n_creds['api_key']  = passwd
         self.reload_client       = True
-        self.logger = logging.getLogger('mano.vim.openstack')
+        self.logger = logging.getLogger('openmano.vim.openstack')
     
     def __setitem__(self,index, value):
         '''Set individuals parameters 
index ff98d19..ee0f960 100644 (file)
@@ -327,7 +327,7 @@ class vimconnector(vimconn.vimconnector):
         vimconn.vimconnector.__init__(self, uuid, name, tenant_id, tenant_name, url, url_admin, user, passwd, log_level, config)
         self.tenant = None
         self.headers_req = {'content-type': 'application/json'}
-        self.logger = logging.getLogger('mano.vim.openvim')
+        self.logger = logging.getLogger('openmano.vim.openvim')
         if tenant_id:
             self.tenant = tenant_id
 
index 20db81e..c5a7392 100644 (file)
@@ -113,14 +113,14 @@ class vimconnector():
         self.user      = user
         self.passwd    = passwd
         self.config    = config
-        self.logger = logging.getLogger('mano.vim.vmware')
-
-        formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
-        ch = logging.StreamHandler()
-        ch.setLevel(log_level)
-        ch.setFormatter(formatter)
-        self.logger.addHandler(ch)
-        self.logger.setLevel( getattr(logging, log_level))
+        self.logger = logging.getLogger('openmano.vim.vmware')
+
+        formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
+        ch = logging.StreamHandler()
+        ch.setLevel(log_level)
+        ch.setFormatter(formatter)
+        self.logger.addHandler(ch)
+        self.logger.setLevel( getattr(logging, log_level))
 
 #        self.logger = logging.getLogger('mano.vim.vmware')