From 8fb9823444b8b759f55e39bdfdcb9fa8d8d507f3 Mon Sep 17 00:00:00 2001
From: Marco Mariani <marco.mariani@nexedi.com>
Date: Sun, 28 Apr 2013 22:33:28 +0200
Subject: [PATCH] refactored setup_logger()

---
 slapos/grid/slapgrid.py | 28 ++++++++++++++++------------
 1 file changed, 16 insertions(+), 12 deletions(-)

diff --git a/slapos/grid/slapgrid.py b/slapos/grid/slapgrid.py
index 21f821171..af7c3b9d3 100644
--- a/slapos/grid/slapgrid.py
+++ b/slapos/grid/slapgrid.py
@@ -242,21 +242,25 @@ def merged_options(args, config):
 
 
 def setup_logger(options):
+  logger = logging.getLogger(__name__)
+
+  if options.get('logfile'):
+    handler = logging.FileHandler(options['logfile'])
+  else:
+    handler = logging.StreamHandler()
+
   if options['verbose']:
-    level = logging.DEBUG
+    handler.setLevel(logging.DEBUG)
   else:
-    level = logging.INFO
-  logging.basicConfig(format='%(asctime)s %(levelname)-8s %(message)s',
-                      level=level,
-                      datefmt='%Y-%m-%dT%H:%M:%S')
-  if options.get('logfile'):
-    console = logging.FileHandler(options['logfile'])
-    console.setLevel(level)
-    console.setFormatter(logging.Formatter(
-        '%(asctime)s %(name)-18s: %(levelname)-8s %(message)s'))
-    logging.getLogger('').addHandler(console)
+    handler.setLevel(logging.INFO)
+
+  formatter = logging.Formatter(fmt='%(asctime)s %(name)-18s: '
+                                '%(levelname)-8s %(message)s',
+                                datefmt='%Y-%m-%dT%H:%M:%S')
+
+  handler.setFormatter(formatter)
+  logger.addHandler(handler)
 
-  logger = logging.getLogger(__name__)
   return logger
 
 
-- 
2.30.9