summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilipp Gesang <phg42.2a@gmail.com>2014-05-19 23:20:24 +0200
committerPhilipp Gesang <phg42.2a@gmail.com>2014-05-19 23:20:24 +0200
commitdd8026cd399d61be7d47bfb3730bb902fefba3b6 (patch)
tree942452378a1c830d7316aabb3c811ab3f77371f1
parent2cc3b67af19a5f66a1ac211e4593ee0ef8403c1e (diff)
downloadcontext-mirror-bot-dd8026cd399d61be7d47bfb3730bb902fefba3b6.tar.gz
write invocation and termination info to syslog
-rw-r--r--OMakefile2
-rw-r--r--context_mirror_bot.ml52
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 <phg42.2a@gmail.com>
* 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));
;;