Shuffle startup order in main process

Initialise the logging code before talking to the database, so we can
log things in the database code. Desired so we can see migrations
being logged as they happen.

Change-Id: I7cd9a01f8390a64669ac5e2efa516401558a48ea
diff --git a/vland.py b/vland.py
index 354c4be..25c854b 100755
--- a/vland.py
+++ b/vland.py
@@ -1,6 +1,6 @@
 #! /usr/bin/python
 
-#  Copyright 2014-2016 Linaro Limited
+#  Copyright 2014-2018 Linaro Limited
 #
 #  This program is free software; you can redistribute it and/or modify
 #  it under the terms of the GNU General Public License as published by
@@ -57,18 +57,33 @@
 
 util = VlanUtil()
 
-print 'Connecting to DB...'
+loglevel = util.set_logging_level(state.config.logging.level)
+
+# Should we log to stderr?
+if state.config.logging.filename is None:
+    logging.basicConfig(level = loglevel,
+                        format = '%(asctime)s %(levelname)-8s %(message)s')
+else:
+    print "Logging to %s" % state.config.logging.filename
+    logging.basicConfig(level = loglevel,
+                        format = '%(asctime)s %(levelname)-8s MAIN %(message)s',
+                        datefmt = '%Y-%m-%d %H:%M:%S %Z',
+                        filename = state.config.logging.filename,
+                        filemode = 'a')
+
+logging.info('%s main daemon starting up', state.banner)
+logging.info('Connecting to DB...')
 state.db = VlanDB(db_name=state.config.database.dbname,
                   username=state.config.database.username, readonly=False)
 
 switches = state.db.all_switches()
-print '  DB knows about %d switches' % len(switches)
+logging.info('DB knows about %d switches', len(switches))
 ports = state.db.all_ports()
-print '  DB knows about %d ports' % len(ports)
+logging.info('DB knows about %d ports', len(ports))
 vlans = state.db.all_vlans()
-print '  DB knows about %d vlans' % len(vlans)
+logging.info('DB knows about %d vlans', len(vlans))
 trunks = state.db.all_trunks()
-print '  DB knows about %d trunks' % len(trunks)
+logging.info('DB knows about %d trunks', len(trunks))
 
 # Initial startup sanity chacking
 
@@ -90,29 +105,6 @@
     print 'for each of your switches may help!'
     print
 
-loglevel = util.set_logging_level(state.config.logging.level)
-
-# Should we log to stderr?
-if state.config.logging.filename is None:
-    logging.basicConfig(level = loglevel,
-                        format = '%(asctime)s %(levelname)-8s %(message)s')
-else:
-    print "Logging to %s" % state.config.logging.filename
-    logging.basicConfig(level = loglevel,
-                        format = '%(asctime)s %(levelname)-8s MAIN %(message)s',
-                        datefmt = '%Y-%m-%d %H:%M:%S %Z',
-                        filename = state.config.logging.filename,
-                        filemode = 'a')
-    logging.info('%s main daemon starting up', state.banner)
-    switches = state.db.all_switches()
-    logging.info('DB knows about %d switches', len(switches))
-    ports = state.db.all_ports()
-    logging.info('DB knows about %d ports', len(ports))
-    vlans = state.db.all_vlans()
-    logging.info('DB knows about %d vlans', len(vlans))
-    trunks = state.db.all_trunks()
-    logging.info('DB knows about %d trunks', len(trunks))
-
 # Now we're done starting up, let the visualisation code talk to the database
 if state.config.visualisation.enabled:
     logging.info('sending db_ok signal')