From: tierno Date: Mon, 20 Aug 2018 11:57:04 +0000 (+0000) Subject: logging to stderr in addition to LOGFILE X-Git-Tag: v5.0.0~31 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=refs%2Fchanges%2F25%2F6425%2F4;p=osm%2FLCM.git logging to stderr in addition to LOGFILE Change-Id: Ia1d0a0fd7e1e1c4b6d3e34a0fae13605ab8173ae --- diff --git a/osm_lcm/__init__.py b/osm_lcm/__init__.py index e3ef989..3a63f8e 100644 --- a/osm_lcm/__init__.py +++ b/osm_lcm/__init__.py @@ -1,2 +1,3 @@ -version = '0.1.11' -version_date = '2018-07-23' +# version moved to lcm.py. uncomment if LCM is installed as library and installed +# version = '0.1.12' +# version_date = '2018-08-23' diff --git a/osm_lcm/lcm.cfg b/osm_lcm/lcm.cfg index c62ee25..c479773 100644 --- a/osm_lcm/lcm.cfg +++ b/osm_lcm/lcm.cfg @@ -4,7 +4,8 @@ #[global] global: loglevel: DEBUG - #logfile: /var/log/osm/lcm.log + logfile: /var/log/osm/lcm.log + # nologging: True # do no log to stdout/stderr #[RO] RO: @@ -12,7 +13,7 @@ RO: port: 9090 tenant: osm loglevel: DEBUG - #logfile: /var/log/osm/lcm-ro.log + # logfile: /var/log/osm/lcm-ro.log #[VCA] VCA: @@ -21,7 +22,7 @@ VCA: user: admin secret: secret loglevel: DEBUG - #logfile: /var/log/osm/lcm-vca.log + # logfile: /var/log/osm/lcm-vca.log #[database] database: @@ -32,7 +33,7 @@ database: user: user password: password loglevel: DEBUG - #logfile: /var/log/osm/lcm-database.log + # logfile: /var/log/osm/lcm-database.log #[storage] storage: @@ -40,7 +41,7 @@ storage: # for local provide file path path: /app/storage loglevel: DEBUG - #logfile: /var/log/osm/lcm-storage.log + # logfile: /var/log/osm/lcm-storage.log #[message] message: @@ -51,4 +52,4 @@ message: host: kafka port: 9092 loglevel: DEBUG - #logfile: /var/log/osm/lcm-message.log + # logfile: /var/log/osm/lcm-message.log diff --git a/osm_lcm/lcm.py b/osm_lcm/lcm.py index 3266914..310c434 100644 --- a/osm_lcm/lcm.py +++ b/osm_lcm/lcm.py @@ -31,6 +31,9 @@ from time import time __author__ = "Alfonso Tierno" min_RO_version = [0, 5, 72] +# uncomment if LCM is installed as library and installed, and get them from __init__.py +lcm_version = '0.1.12' +lcm_version_date = '2018-08-23' class LcmException(Exception): @@ -166,12 +169,12 @@ class Lcm: config["database"]["logger_name"] = "lcm.db" config["storage"]["logger_name"] = "lcm.fs" config["message"]["logger_name"] = "lcm.msg" - if "logfile" in config["global"]: + if config["global"].get("logfile"): file_handler = logging.handlers.RotatingFileHandler(config["global"]["logfile"], maxBytes=100e6, backupCount=9, delay=0) file_handler.setFormatter(log_formatter_simple) self.logger.addHandler(file_handler) - else: + if not config["global"].get("nologging"): str_handler = logging.StreamHandler() str_handler.setFormatter(log_formatter_simple) self.logger.addHandler(str_handler) @@ -183,14 +186,14 @@ class Lcm: for k1, logname in {"message": "lcm.msg", "database": "lcm.db", "storage": "lcm.fs"}.items(): config[k1]["logger_name"] = logname logger_module = logging.getLogger(logname) - if "logfile" in config[k1]: + if config[k1].get("logfile"): file_handler = logging.handlers.RotatingFileHandler(config[k1]["logfile"], maxBytes=100e6, backupCount=9, delay=0) file_handler.setFormatter(log_formatter_simple) logger_module.addHandler(file_handler) - if "loglevel" in config[k1]: + if config[k1].get("loglevel"): logger_module.setLevel(config[k1]["loglevel"]) - # self.logger.critical("starting osm/lcm version {} {}".format(lcm_version, lcm_version_date)) + self.logger.critical("starting osm/lcm version {} {}".format(lcm_version, lcm_version_date)) self.n2vc = N2VC( log=self.logger, server=config['VCA']['host'], diff --git a/setup.py b/setup.py index 45de1f8..47ca680 100644 --- a/setup.py +++ b/setup.py @@ -33,7 +33,7 @@ setup( "git+https://osm.etsi.org/gerrit/osm/common.git@master#egg=osm-common-0.1.4" ], install_requires=[ - 'pymongo', 'PyYAML', + 'pymongo', 'PyYAML', 'aiohttp' # 'osm-common', ], setup_requires=['setuptools-version-command'],