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

Nikita Spiridonov nspiridonov at virtuozzo.com
Thu Apr 21 05:46:31 PDT 2016


move log_uncaught_exception function from p.haul and p.haul-service
to util.py file to avoid code duplication.

Signed-off-by: Nikita Spiridonov <nspiridonov at virtuozzo.com>
---
 p.haul         |    6 +-----
 p.haul-service |    6 +-----
 phaul/util.py  |    4 ++++
 3 files changed, 6 insertions(+), 10 deletions(-)

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):
-- 
1.7.1



More information about the CRIU mailing list