From 73ad9e4d8ceff08bd6a9e799cb8b48ad914cd35a Mon Sep 17 00:00:00 2001 From: tierno Date: Mon, 12 Sep 2016 18:11:11 +0200 Subject: [PATCH] v0.4.52 fixes logging name mismatching. Add individual log files per module Change-Id: I15c922fb2e6135662e2d12e2898e790be9fb3602 Signed-off-by: tierno --- httpserver.py | 4 +++- nfvo.py | 3 ++- openmano_schemas.py | 7 ++++++- openmanod.cfg | 13 ++++++++++--- openmanod.py | 27 ++++++++++++++++++++++----- vimconn.py | 2 +- vimconn_openstack.py | 2 +- vimconn_openvim.py | 2 +- vimconn_vmware.py | 16 ++++++++-------- 9 files changed, 54 insertions(+), 22 deletions(-) diff --git a/httpserver.py b/httpserver.py index 83ed06f4..a4e7fb9b 100644 --- a/httpserver.py +++ b/httpserver.py @@ -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 7dbd51d9..da2cfa07 100644 --- 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): diff --git a/openmano_schemas.py b/openmano_schemas.py index 3d95dc7d..8af46826 100644 --- a/openmano_schemas.py +++ b/openmano_schemas.py @@ -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, diff --git a/openmanod.cfg b/openmanod.cfg index e4dc4e1d..0540e1b6 100644 --- a/openmanod.cfg +++ b/openmanod.cfg @@ -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 diff --git a/openmanod.py b/openmanod.py index 69e6755b..5294a9ff 100755 --- a/openmanod.py +++ b/openmanod.py @@ -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: diff --git a/vimconn.py b/vimconn.py index 7e82590d..e6e04215 100644 --- a/vimconn.py +++ b/vimconn.py @@ -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 diff --git a/vimconn_openstack.py b/vimconn_openstack.py index 314027d3..80f47f5e 100644 --- a/vimconn_openstack.py +++ b/vimconn_openstack.py @@ -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 diff --git a/vimconn_openvim.py b/vimconn_openvim.py index ff98d19d..ee0f9600 100644 --- a/vimconn_openvim.py +++ b/vimconn_openvim.py @@ -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 diff --git a/vimconn_vmware.py b/vimconn_vmware.py index 20db81e9..c5a7392a 100644 --- a/vimconn_vmware.py +++ b/vimconn_vmware.py @@ -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') -- 2.25.1