[umpire] Enable shop floor logging

The ExistingLogWriter outputs log into an existing log file.

BUG=chrome-os-partner:32244
TEST=manual
  touch /var/db/factory/umpire/BOARD/log/shop_floor.log
  check the log content after shop floor operation.

Change-Id: I46f32ebae8f3f0300950ac24ac3a2fde65828273
Reviewed-on: https://chromium-review.googlesource.com/218085
Reviewed-by: Rong Chang <rongchang@chromium.org>
Commit-Queue: Rong Chang <rongchang@chromium.org>
Tested-by: Rong Chang <rongchang@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/219655
Reviewed-by: Cheng-Yi Chiang <cychiang@chromium.org>
diff --git a/py/umpire/service/shop_floor.py b/py/umpire/service/shop_floor.py
index e49a96d..13b9ee8 100644
--- a/py/umpire/service/shop_floor.py
+++ b/py/umpire/service/shop_floor.py
@@ -15,6 +15,19 @@
 # TODO(rongchang): Check why symlink doesn't work.
 SHOP_FLOOR_FCGI = 'usr/local/factory/py/umpire/shop_floor_launcher.py'
 PROCESS_NAME_PREFIX = 'shop_floor_'
+LOG_FILE_NAME = 'shop_floor.log'
+
+
+class ExistingLogWriter(object):
+  """ExistingLogWriter writes data to existing file only."""
+  def __init__(self, path):
+    super(ExistingLogWriter, self).__init__()
+    self._path = path
+
+  def write(self, data):
+    if os.path.isfile(self._path):
+      with open(self._path, 'a') as log:
+        log.write(data)
 
 
 class ShopFloorService(umpire_service.UmpireService):
@@ -30,6 +43,7 @@
   def __init__(self):
     super(ShopFloorService, self).__init__()
     self.properties['num_shopfloor_handlers'] = 0
+    self.log = None
 
   def CreateProcesses(self, dummy_config, env):
     """Creates list of shop floor processes via config.
@@ -41,6 +55,7 @@
     Returns:
       A list of ServiceProcess.
     """
+    self.log = ExistingLogWriter(os.path.join(env.log_dir, LOG_FILE_NAME))
     active_bundles = env.config.GetActiveBundles()
     processes = []
     for bundle in active_bundles:
diff --git a/py/umpire/shop_floor_launcher.py b/py/umpire/shop_floor_launcher.py
index edc5c81..e1aee02 100755
--- a/py/umpire/shop_floor_launcher.py
+++ b/py/umpire/shop_floor_launcher.py
@@ -140,4 +140,6 @@
 
 
 if __name__ == '__main__':
+  logging.basicConfig(level=logging.DEBUG,
+                      format='%(levelname)5s %(message)s')
   main()