From dd8026cd399d61be7d47bfb3730bb902fefba3b6 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Mon, 19 May 2014 23:20:24 +0200 Subject: write invocation and termination info to syslog --- OMakefile | 2 +- context_mirror_bot.ml | 52 ++++++++++++++++++++++++++++++++++++--------------- 2 files changed, 38 insertions(+), 16 deletions(-) diff --git a/OMakefile b/OMakefile index 602ea95..c13a2dc 100644 --- a/OMakefile +++ b/OMakefile @@ -2,7 +2,7 @@ USE_OCAMLFIND = true -OCAMLPACKS[] = curl uri xmlm unix fileutils str +OCAMLPACKS[] = curl uri xmlm unix fileutils str syslog #core #async #uri diff --git a/context_mirror_bot.ml b/context_mirror_bot.ml index 148dd37..57b1e84 100644 --- a/context_mirror_bot.ml +++ b/context_mirror_bot.ml @@ -23,13 +23,10 @@ * Contact: Philipp Gesang * Bitbucket: https://bitbucket.org/phg/context-mirror * - ****************************************************************************** - * - * TODO - * * logging - * *****************************************************************************) +let t_start = Unix.gettimeofday () + type context_src = { name : string; url : string; @@ -175,6 +172,14 @@ let msg ?lev:(lev=0) str = let err str = Printf.eprintf "[bot %s: error] %s\n%!" (timestamp ()) str +let logger = Syslog.openlog Sys.argv.(0);; + +let log_info msg = + Syslog.syslog logger `LOG_INFO msg + +let log_debug msg = + Syslog.syslog logger `LOG_DEBUG msg + let dir_exists path = try let dh = Unix.opendir path in @@ -747,18 +752,32 @@ let run_push () = let run_files () = Git.install_files () +let print_kind = function + | Status -> "status" + | Check -> "check" + | Update -> "update" + | Prepare -> "prepare" + | Download -> "download" + | Clean -> "cleanup" + | Push -> "push" + | Files -> "files" + | Nil -> "()" let dispatch_job j = + log_info (Printf.sprintf + "started in %s mode at %s." + (print_kind j.kind) + (format_time t_start)); match j.kind with - | Status -> run_status () - | Check -> run_check () - | Update -> run_update () - | Prepare -> run_prepare () - | Download -> run_download () - | Clean -> run_cleanup () - | Push -> run_push () - | Files -> run_files () - | Nil -> () + | Status -> run_status () + | Check -> run_check () + | Update -> run_update () + | Prepare -> run_prepare () + | Download -> run_download () + | Clean -> run_cleanup () + | Push -> run_push () + | Files -> run_files () + | Nil -> () (****************************************************************************** * main @@ -767,6 +786,9 @@ let dispatch_job j = let () = let job = parse_argv () in Git.set_path repo_dir; - dispatch_job job + dispatch_job job; + log_info (Printf.sprintf + "mirror bot finished in %.2f ms." + (Unix.gettimeofday () -. t_start)); ;; -- cgit v1.2.3