[CRIU] [PATCH 2/3] p.haul: add --log-file option
Nikita Spiridonov
nspiridonov at odin.com
Wed Sep 30 09:48:21 PDT 2015
Add --log-file option to p.haul and p.haul-service needed to specify
log name. Configure p.haul and p.haul-service loggers.
Signed-off-by: Nikita Spiridonov <nspiridonov at odin.com>
---
p.haul | 11 +++++++++++
p.haul-service | 12 ++++++++++++
2 files changed, 23 insertions(+), 0 deletions(-)
diff --git a/p.haul b/p.haul
index 896b1fa..aea7971 100755
--- a/p.haul
+++ b/p.haul
@@ -2,6 +2,7 @@
import sys
import argparse
+import logging
import phaul.p_haul_iters as ph_iters
import phaul.images as ph_images
import phaul.criu_api as ph_criu_api
@@ -30,9 +31,19 @@ parser.add_argument("--img-path", help="Dirctory where to put images", default=p
parser.add_argument("--pid-root", help="Path to tree's FS root")
parser.add_argument("--force", help="Don't do any sanity (CPU compat) checks", default=False, action='store_true')
parser.add_argument("--port", help="Port where to haul", type=int, default=ph_xem_rpc.rpc_port)
+parser.add_argument("--log-file", help="Write logging messages to specified file")
args = parser.parse_args()
+# Configure logging
+logging.basicConfig(filename=args.log_file, filemode="w", level=logging.INFO,
+ format="%(asctime)s.%(msecs)03d: %(message)s", datefmt="%H:%M:%S")
+
+# Setup hook to log uncaught exceptions
+def log_uncaught_exception(type, value, traceback):
+ logging.error(value, exc_info=(type, value, traceback))
+sys.excepthook = log_uncaught_exception
+
args_dict = vars(args)
ph_type = (args_dict.pop("type"), args_dict.pop("id"))
dst = (args_dict.pop("to"), args_dict.pop("port"))
diff --git a/p.haul-service b/p.haul-service
index 65ba635..76e5b3e 100755
--- a/p.haul-service
+++ b/p.haul-service
@@ -1,16 +1,28 @@
#!/usr/bin/env python
+import sys
import signal
import argparse
+import logging
import phaul.xem_rpc as ph_xem_rpc
import phaul.p_haul_service as ph_srv
parser = argparse.ArgumentParser("Process HAULer service server")
parser.add_argument("--bind-addr", help="IP to bind to", type=str, default="0.0.0.0")
parser.add_argument("--bind-port", help="Port to bind to", type=int, default=ph_xem_rpc.rpc_port)
+parser.add_argument("--log-file", help="Write logging messages to specified file")
args = parser.parse_args()
+# Configure logging
+logging.basicConfig(filename=args.log_file, filemode="w", level=logging.INFO,
+ format="%(asctime)s.%(msecs)03d: %(message)s", datefmt="%H:%M:%S")
+
+# Setup hook to log uncaught exceptions
+def log_uncaught_exception(type, value, traceback):
+ logging.error(value, exc_info=(type, value, traceback))
+sys.excepthook = log_uncaught_exception
+
host = (args.bind_addr, args.bind_port)
sfd = None
--
1.7.1
More information about the CRIU
mailing list