Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/baselib/ocsigen_commandline.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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)");
Expand Down
2 changes: 1 addition & 1 deletion src/baselib/ocsigen_config.ml.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 17 additions & 8 deletions src/baselib/ocsigen_messages.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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. *)
Expand Down Expand Up @@ -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];
Expand All @@ -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 ()
Expand Down Expand Up @@ -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

Expand Down