From d3ad5ac2944a70a38203a4f3cc1486982b5853d6 Mon Sep 17 00:00:00 2001 From: Jan Rochel Date: Thu, 18 Jul 2019 17:08:21 +0200 Subject: [PATCH] fix logging issues - all sections (including "access") are now prefixed by "ocsigen:" - default logging level is only applied to "ocsigen:*" instead of "*" - always log access.log (wasn't previously the case) - only level warning/error/fatal points to stderr, otherwise to stdout --- src/baselib/ocsigen_commandline.ml | 4 ++-- src/baselib/ocsigen_config.ml.in | 2 +- src/baselib/ocsigen_messages.ml | 25 +++++++++++++++++-------- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/baselib/ocsigen_commandline.ml b/src/baselib/ocsigen_commandline.ml index dc7a88a34..4830114e8 100644 --- a/src/baselib/ocsigen_commandline.ml +++ b/src/baselib/ocsigen_commandline.ml @@ -25,8 +25,8 @@ let cmdline : unit = "Alternate config file (default "^ Ocsigen_config.get_config_file() ^")"); ("--config", Arg.String set_configfile, "Alternate config file (default "^ Ocsigen_config.get_config_file() ^")"); - ("-s", Arg.Unit set_silent, "Silent mode (error messages in errors.log only)"); - ("--silent", Arg.Unit set_silent, "Silent mode (error messages in errors.log only)"); + ("-s", Arg.Unit set_silent, "silent mode (no logging to console; does not affect *.log files)"); + ("--silent", Arg.Unit set_silent, "silent mode (no logging to console; does not affect *.log files)"); ("-p", Arg.String set_pidfile, "Specify a file where to write the PIDs of servers"); ("--pidfile", Arg.String set_pidfile, "Specify a file where to write the PIDs of servers"); ("-v", Arg.Unit set_verbose, "Verbose mode (notice)"); diff --git a/src/baselib/ocsigen_config.ml.in b/src/baselib/ocsigen_config.ml.in index 9114c9a38..a333600b9 100644 --- a/src/baselib/ocsigen_config.ml.in +++ b/src/baselib/ocsigen_config.ml.in @@ -80,7 +80,7 @@ let set_syslog_facility f = syslog_facility := f; logdir := None let set_configfile s = config_file := s let set_pidfile s = pidfile := Some s let set_mimefile s = mimefile := s -let () = Lwt_log.add_rule "*" Lwt_log.Warning (* without --verbose *) +let () = Lwt_log.add_rule "ocsigen:*" Lwt_log.Warning (* without --verbose *) let set_verbose () = verbose := true; Lwt_log.add_rule "ocsigen:*" Lwt_log.Notice diff --git a/src/baselib/ocsigen_messages.ml b/src/baselib/ocsigen_messages.ml index f2e3a3899..417e95a91 100644 --- a/src/baselib/ocsigen_messages.ml +++ b/src/baselib/ocsigen_messages.ml @@ -25,16 +25,19 @@ let warning_file = "warnings.log" let error_file = "errors.log" -let access_sect = Lwt_log.Section.make "access" +let access_sect = Lwt_log.Section.make "ocsigen:access" let full_path f = Filename.concat (Ocsigen_config.get_logdir ()) f let error_log_path () = full_path error_file let stderr = Lwt_log.channel `Keep Lwt_io.stderr () +let stdout = Lwt_log.channel `Keep Lwt_io.stdout () let loggers = ref [] +let access_logger = ref Lwt_log_core.null + let open_files ?(user = Ocsigen_config.get_user ()) ?(group = Ocsigen_config.get_group ()) () = (* CHECK: we are closing asynchronously! That should be ok, though. *) @@ -66,6 +69,7 @@ let open_files ?(user = Ocsigen_config.get_user ()) ?(group = Ocsigen_config.get in open_log access_file >>= fun acc -> + access_logger := acc; open_log warning_file >>= fun war -> open_log error_file >>= fun err -> loggers := [acc; war; err]; @@ -74,14 +78,16 @@ let open_files ?(user = Ocsigen_config.get_user ()) ?(group = Ocsigen_config.get Lwt_log.broadcast [Lwt_log.dispatch (fun sect lev -> - if sect = access_sect then acc else - match lev with - | Lwt_log.Error | Lwt_log.Fatal -> err - | Lwt_log.Warning -> war - | _ -> Lwt_log.null); + match lev with + | Lwt_log.Error | Lwt_log.Fatal -> err + | Lwt_log.Warning -> war + | _ -> Lwt_log.null); Lwt_log.dispatch (fun sect lev -> - if Ocsigen_config.get_silent () then Lwt_log.null else stderr)]; + if Ocsigen_config.get_silent () then Lwt_log.null else + match lev with + | Lwt_log.Warning | Lwt_log.Error | Lwt_log.Fatal -> stderr + | _ -> stdout)]; let gid = match group with | None -> Unix.getgid () @@ -109,7 +115,10 @@ let open_files ?(user = Ocsigen_config.get_user ()) ?(group = Ocsigen_config.get (****) -let accesslog s = Lwt_log.ign_notice ~section:access_sect s +let accesslog s = + (* not really fatal, but log in all cases; does not affect console *) + Lwt_log.ign_fatal ~section:access_sect ~logger:!access_logger s; + Lwt_log.ign_notice ~section:access_sect s let errlog ?section s = Lwt_log.ign_error ?section s