[SEBA-157]
Separate Structlog logging config into it's own config file, so it can
be more easily changed during deployment
Change-Id: I1c8149690c65ad2e7e3f68688a4d538e56e29ac1
diff --git a/netconf/logconfig.yml b/netconf/logconfig.yml
new file mode 100644
index 0000000..783b071
--- /dev/null
+++ b/netconf/logconfig.yml
@@ -0,0 +1,51 @@
+---
+# Copyright 2017-present Open Networking Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+version: 1
+
+formatters:
+ brief:
+ format: '%(message)s'
+ default:
+ format: '%(asctime)s.%(msecs)03d %(levelname)-8s %(threadName)s %(module)s.%(funcName)s %(message)s'
+ datefmt: '%Y%m%dT%H%M%S'
+
+handlers:
+ console:
+ class : logging.StreamHandler
+ level: DEBUG
+ formatter: default
+ stream: ext://sys.stdout
+ localRotatingFile:
+ class: logging.handlers.RotatingFileHandler
+ filename: voltha.log
+ formatter: default
+ maxBytes: 2097152
+ backupCount: 10
+ level: DEBUG
+ null:
+ class: logging.NullHandler
+
+loggers:
+ amqp:
+ handlers: [null]
+ propagate: False
+ conf:
+ propagate: False
+ '': # root logger
+ handlers: [console, localRotatingFile]
+ level: INFO # this can be bumped up/down by -q and -v command line
+ # options
+ propagate: False
diff --git a/netconf/main.py b/netconf/main.py
index 6f096a8..41a4349 100755
--- a/netconf/main.py
+++ b/netconf/main.py
@@ -33,6 +33,7 @@
defs = dict(
config=os.environ.get('CONFIG', './netconf.yml'),
+ logconfig=os.environ.get('LOGCONFIG', './logconfig.yml'),
consul=os.environ.get('CONSUL', 'localhost:8500'),
external_host_address=os.environ.get('EXTERNAL_HOST_ADDRESS',
get_my_primary_local_ipv4()),
@@ -65,6 +66,15 @@
default=defs['config'],
help=_help)
+ _help = ('Path to logconfig.yml config file (default: %s). '
+ 'If relative, it is relative to main.py of voltha.'
+ % defs['logconfig'])
+ parser.add_argument('-l', '--logconfig',
+ dest='logconfig',
+ action='store',
+ default=defs['logconfig'],
+ help=_help)
+
_help = '<hostname>:<port> to consul agent (default: %s)' % defs['consul']
parser.add_argument(
'-C', '--consul', dest='consul', action='store',
@@ -203,8 +213,9 @@
return args
-def load_config(args):
- path = args.config
+def load_config(args, configname='config'):
+ argdict = vars(args)
+ path = argdict[configname]
if path.startswith('.'):
dir = os.path.dirname(os.path.abspath(__file__))
path = os.path.join(dir, path)
@@ -234,9 +245,10 @@
self.args = args = parse_args()
self.config = load_config(args)
+ self.logconfig = load_config(args, 'logconfig')
verbosity_adjust = (args.verbose or 0) - (args.quiet or 0)
- self.log = setup_logging(self.config.get('logging', {}),
+ self.log = setup_logging(self.logconfig,
args.instance_id,
verbosity_adjust=verbosity_adjust)
diff --git a/netconf/netconf.yml b/netconf/netconf.yml
index 24aca85..d255bf2 100644
--- a/netconf/netconf.yml
+++ b/netconf/netconf.yml
@@ -1,3 +1,4 @@
+---
# Copyright 2017-present Open Networking Foundation
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -11,40 +12,3 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
-logging:
- version: 1
-
- formatters:
- brief:
- format: '%(message)s'
- default:
- format: '%(asctime)s.%(msecs)03d %(levelname)-8s %(module)s.%(funcName)s %(message)s'
- datefmt: '%Y%m%dT%H%M%S'
-
- handlers:
- console:
- class : logging.StreamHandler
- level: DEBUG
- formatter: default
- stream: ext://sys.stdout
- localRotatingFile:
- class: logging.handlers.RotatingFileHandler
- filename: netconf.log
- formatter: default
- maxBytes: 2097152
- backupCount: 10
- level: DEBUG
- null:
- class: logging.NullHandler
-
- loggers:
- amqp:
- handlers: [null]
- propagate: False
- conf:
- propagate: False
- '': # root logger
- handlers: [console, localRotatingFile]
- level: INFO # this can be bumped up/down by -q and -v command line
- # options
- propagate: False