[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/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