[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
diff --git a/ofagent/logconfig.yml b/ofagent/logconfig.yml
new file mode 100644
index 0000000..783b071
--- /dev/null
+++ b/ofagent/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/ofagent/main.py b/ofagent/main.py
index 06c2ae3..144a0ad 100755
--- a/ofagent/main.py
+++ b/ofagent/main.py
@@ -28,6 +28,7 @@
defs = dict(
config=os.environ.get('CONFIG', './ofagent.yml'),
+ logconfig=os.environ.get('LOGCONFIG', './logconfig.yml'),
consul=os.environ.get('CONSUL', 'localhost:8500'),
controller=os.environ.get('CONTROLLER', 'localhost:6653'),
external_host_address=os.environ.get('EXTERNAL_HOST_ADDRESS',
@@ -55,6 +56,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',
@@ -172,8 +182,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)
@@ -203,12 +214,14 @@
self.args = args = parse_args()
self.config = load_config(args)
+ self.logconfig = load_config(args, 'logconfig')
+
# May want to specify the gRPC timeout as an arg (in future)
# Right now, set a default value
self.grpc_timeout = 10
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/ofagent/ofagent.yml b/ofagent/ofagent.yml
index a0e2cdd..863a8bd 100644
--- a/ofagent/ofagent.yml
+++ b/ofagent/ofagent.yml
@@ -1,3 +1,4 @@
+---
# Copyright 2017-present Open Networking Foundation
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -11,40 +12,4 @@
# 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: ofagent.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/requirements.txt b/requirements.txt
index 56cb356..4ed57f4 100755
--- a/requirements.txt
+++ b/requirements.txt
@@ -16,6 +16,7 @@
jinja2==2.8
jsonpatch==1.16
kafka_python==1.3.5
+kafkaloghandler==0.8.0
klein==17.10.0
kubernetes==5.0.0
netaddr==0.7.19
diff --git a/voltha/logconfig.yml b/voltha/logconfig.yml
new file mode 100644
index 0000000..783b071
--- /dev/null
+++ b/voltha/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/voltha/main.py b/voltha/main.py
index 36c6013..a2f1df2 100755
--- a/voltha/main.py
+++ b/voltha/main.py
@@ -52,6 +52,7 @@
defs = dict(
version_file='./VERSION',
config=os.environ.get('CONFIG', './voltha.yml'),
+ logconfig=os.environ.get('LOGCONFIG', './logconfig.yml'),
container_name_regex=os.environ.get('CORE_NUMBER_EXTRACTOR', '^.*\.([0-9]+)\..*$'),
consul=os.environ.get('CONSUL', 'localhost:8500'),
etcd=os.environ.get('ETCD', 'localhost:2379'),
@@ -84,6 +85,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 = 'Regular expression for extracting core number from container name (default: %s)' % defs['container_name_regex']
parser.add_argument(
'-X', '--core-number-extractor', dest='container_name_regex', action='store',
@@ -256,8 +266,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)
@@ -283,9 +294,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)
self.log.info('core-number-extractor', regex=args.container_name_regex)
diff --git a/voltha/voltha.yml b/voltha/voltha.yml
index e7b0340..93262fb 100644
--- a/voltha/voltha.yml
+++ b/voltha/voltha.yml
@@ -1,3 +1,4 @@
+---
# Copyright 2017-present Open Networking Foundation
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -11,43 +12,6 @@
# 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 %(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
core:
management_vlan: 4091