[3/4] p.haul: move log_uncaught_exception function to util.py

Submitted by Nikita Spiridonov on April 21, 2016, 12:46 p.m.

Details

Message ID 1461242792-635567-4-git-send-email-nspiridonov@virtuozzo.com
State New
Series "improve p.haul logging"
Headers show

Patch hide | download patch | download mbox

diff --git a/p.haul b/p.haul
index 8a36d90..241632d 100755
--- a/p.haul
+++ b/p.haul
@@ -22,10 +22,6 @@  import phaul.connection
 #
 
 
-def log_uncaught_exception(type, value, traceback):
-	logging.error(value, exc_info=(type, value, traceback))
-
-
 # Parse arguments
 args = phaul.args_parser.parse_client_args()
 
@@ -35,7 +31,7 @@  logging.basicConfig(filename=args.log_file, filemode="a", level=logging.INFO,
 	datefmt="%H:%M:%S")
 
 # Setup hook to log uncaught exceptions
-sys.excepthook = log_uncaught_exception
+sys.excepthook = phaul.util.log_uncaught_exception
 
 phaul.util.log_header()
 logging.info("Starting p.haul")
diff --git a/p.haul-service b/p.haul-service
index 6fe33ea..15a3e07 100755
--- a/p.haul-service
+++ b/p.haul-service
@@ -10,10 +10,6 @@  import phaul.service
 import phaul.connection
 
 
-def log_uncaught_exception(type, value, traceback):
-	logging.error(value, exc_info=(type, value, traceback))
-
-
 def fin(foo, bar):
 	global stop_fd
 	logging.info("Stop by %d", foo)
@@ -29,7 +25,7 @@  logging.basicConfig(filename=args.log_file, filemode="a", level=logging.INFO,
 	datefmt="%H:%M:%S")
 
 # Setup hook to log uncaught exceptions
-sys.excepthook = log_uncaught_exception
+sys.excepthook = phaul.util.log_uncaught_exception
 
 phaul.util.log_header()
 logging.info("Starting p.haul service")
diff --git a/phaul/util.py b/phaul/util.py
index 9cca073..1f17e5b 100644
--- a/phaul/util.py
+++ b/phaul/util.py
@@ -80,6 +80,10 @@  def makedirs(dirpath):
 			raise
 
 
+def log_uncaught_exception(type, value, traceback):
+	logging.error(value, exc_info=(type, value, traceback))
+
+
 def log_header():
 	OFFSET_LINES_COUNT = 3
 	for i in range(OFFSET_LINES_COUNT):