Skip to content

Commit f1b26ec

Browse files
committed
log: add critical due to error level inflation
1 parent 4f3f932 commit f1b26ec

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

log.ml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ let set_utc () = State.utc_timezone := true
133133
By default, it reads the configuration in the environment variable [DEVKIT_LOG]
134134
which can be overwritten using the optional [process_name] parameter.
135135
136-
The value of environment variable should match the following grammar: [(\[<facil|prefix*>=\]debug|info|warn|error\[,\])*]
136+
The value of environment variable should match the following grammar: [(\[<facil|prefix*>=\]debug|info|warn|error|critical\[,\])*]
137137
138138
@raise Failure on invalid level values of wrong format
139139
*)
@@ -184,12 +184,14 @@ let debug_s = make_s debug_s in
184184
let warn_s = make_s warn_s in
185185
let info_s = make_s info_s in
186186
let error_s = make_s error_s in
187+
let critical_s = make_s critical_s in
187188
let put_s level = make_s (put_s level) in
188189
object
189190
method debug_s = debug_s
190191
method warn_s = warn_s
191192
method info_s = info_s
192193
method error_s = error_s
194+
method critical_s = critical_s
193195
method put_s = put_s
194196

195197
(* expecting direct inlining to be faster but it is not o_O
@@ -201,6 +203,7 @@ method debug : 'a. 'a pr = make debug_s
201203
method warn : 'a. 'a pr = make warn_s
202204
method info : 'a. 'a pr = make info_s
203205
method error : 'a. 'a pr = make error_s
206+
method critical : 'a. 'a pr = make critical_s
204207
method put : 'a. Logger.level -> 'a pr = fun level -> make (put_s level)
205208

206209
method allow (level:Logger.level) = Logger.set_filter facil level

logger.ml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,39 @@
11

22
open Printf
33

4-
type level = [`Debug | `Info | `Warn | `Error | `Nothing]
4+
type level = [`Debug | `Info | `Warn | `Error | `Critical | `Nothing]
55
type facil = { name : string; mutable show : int; }
66
let int_level = function
77
| `Debug -> 0
88
| `Info -> 1
99
| `Warn -> 2
1010
| `Error -> 3
11+
| `Critical -> 4
1112
| `Nothing -> 100
1213
let set_filter facil level = facil.show <- int_level level
1314
let get_level facil = match facil.show with
1415
| 0 -> `Debug
1516
| 1 -> `Info
1617
| 2 -> `Warn
18+
| 3 -> `Error
1719
| x when x = 100 -> `Nothing
18-
| _ -> `Error (* ! *)
20+
| _ -> `Critical (* ! *)
1921
let allowed facil level = level <> `Nothing && int_level level >= facil.show
2022

2123
let string_level = function
2224
| `Debug -> "debug"
2325
| `Info -> "info"
2426
| `Warn -> "warn"
2527
| `Error -> "error"
28+
| `Critical -> "critical"
2629
| `Nothing -> "nothing"
2730

2831
let level = function
2932
| "info" -> `Info
3033
| "debug" -> `Debug
3134
| "warn" -> `Warn
3235
| "error" -> `Error
36+
| "critical" -> `Critical
3337
| "nothing" -> `Nothing
3438
| s -> Exn.fail "unrecognized level %s" s
3539

@@ -86,11 +90,13 @@ module Make(T : Put) = struct
8690
let info_s = T.put `Info
8791
let warn_s = T.put `Warn
8892
let error_s = T.put `Error
93+
let critical_s = T.put `Critical
8994
let put_s = T.put
9095

9196
let debug f fmt = ksprintf (debug_s f) fmt
9297
let info f fmt = ksprintf (info_s f) fmt
9398
let warn f fmt = ksprintf (warn_s f) fmt
9499
let error f fmt = ksprintf (error_s f) fmt
100+
let critical f fmt = ksprintf (critical_s f) fmt
95101

96102
end

0 commit comments

Comments
 (0)