Skip to content

Commit

Permalink
Make verbose mode opt-in
Browse files Browse the repository at this point in the history
The default mode of overriding any user created log reporter and log
level filter can be confusing. I'm not fully convinced about setting
up a log reporter/level behind the scenes (i don't mind shipping a log
reporter with opium), but maybe having this be opt-in is enough.

Closes #221
  • Loading branch information
anuragsoni committed Nov 22, 2020
1 parent 8983b46 commit 55605b5
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions opium/src/app.ml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type t =
; backlog : int option
; ssl : ([ `Crt_file_path of string ] * [ `Key_file_path of string ]) option
; debug : bool
; quiet : bool
; verbose : bool
; routes : (Httpaf.Method.t * Route.t * Rock.Handler.t) list
; middlewares : Rock.Middleware.t list
; name : string
Expand Down Expand Up @@ -71,7 +71,7 @@ let empty =
; backlog = None
; ssl = None
; debug = false
; quiet = false
; verbose = false
; routes = []
; middlewares = []
; not_found = default_not_found
Expand All @@ -86,10 +86,10 @@ let create_router routes =
Middleware_router.add router ~meth ~route ~action)
;;

let attach_middleware { quiet; debug; routes; middlewares; _ } =
let attach_middleware { verbose; debug; routes; middlewares; _ } =
[ Some (routes |> create_router |> Middleware_router.m) ]
@ List.map ~f:Option.some middlewares
@ [ (if not quiet then Some Middleware_logger.m else None)
@ [ (if verbose then Some Middleware_logger.m else None)
; (if debug then Some Middleware_debugger.m else None)
]
|> List.filter_opt
Expand Down Expand Up @@ -149,7 +149,7 @@ let start app =
(* We initialize the middlewares first, because the logger middleware initializes the
logger. *)
let middlewares = attach_middleware app in
if not app.quiet
if app.verbose
then (
Logs.set_reporter (Logs_fmt.reporter ());
Logs.set_level (Some Logs.Info));
Expand Down Expand Up @@ -208,7 +208,7 @@ let cmd_run
print_routes
print_middleware
debug
quiet
verbose
_errors
=
let map2 ~f a b =
Expand All @@ -224,7 +224,7 @@ let cmd_run
| Some s, _ | None, Some s -> Some s
| None, None -> None
in
let app = { app with debug; quiet; host; port; ssl } in
let app = { app with debug; verbose; host; port; ssl } in
if print_routes
then (
let routes = app.routes in
Expand Down Expand Up @@ -276,9 +276,9 @@ module Cmds = struct
Arg.(value & flag & info [ "d"; "debug" ] ~doc)
;;

let quiet =
let doc = "disable verbose mode" in
Arg.(value & flag & info [ "q"; "quiet" ] ~doc)
let verbose =
let doc = "enable verbose mode" in
Arg.(value & flag & info [ "v"; "verbose" ] ~doc)
;;

let errors =
Expand All @@ -298,7 +298,7 @@ module Cmds = struct
$ routes
$ middleware
$ debug
$ quiet
$ verbose
$ errors
;;

Expand Down

0 comments on commit 55605b5

Please sign in to comment.