Skip to content

Commit

Permalink
Improve logger
Browse files Browse the repository at this point in the history
  • Loading branch information
Kruhlmann committed Jun 16, 2024
1 parent 82e0f56 commit b1619f8
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions lib/data/platform/cookie.ml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ let create login domain =
in
let* body_str = Cohttp_lwt.Body.to_string body in
let cookies = extract_cookies @@ Cohttp.Response.headers response in
let* _ = Logger.Async.debug ~m:"Cookie" ~f:"create" "Cookie retrieved" in
let application_gateway_affinity_cors = get_cookie_value cookies "ApplicationGatewayAffinityCORS" in
let application_gateway_affinity = get_cookie_value cookies "ApplicationGatewayAffinity" in
let reliclink = get_cookie_value cookies "reliclink" in
Expand Down
3 changes: 2 additions & 1 deletion lib/logger/async.ml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
let log ?m ?f level fmt =
let ksprintf_logger str =
let formatted_msg = Base.format_message ?m ?f level str in
Lwt_io.printf "%s" formatted_msg
match level with Level.FATAL -> Lwt.fail_with formatted_msg | _ -> Lwt_io.printf "%s" formatted_msg
in
Printf.ksprintf ksprintf_logger fmt
;;
Expand All @@ -10,3 +10,4 @@ let debug ?m ?f fmt = log ?m ?f Level.DEBUG fmt
let info ?m ?f fmt = log ?m ?f Level.INFO fmt
let warn ?m ?f fmt = log ?m ?f Level.WARN fmt
let error ?m ?f fmt = log ?m ?f Level.ERROR fmt
let fatal ?m ?f fmt = log ?m ?f Level.FATAL fmt
4 changes: 3 additions & 1 deletion lib/logger/level.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ type t =
| INFO
| WARN
| ERROR
| FATAL

let to_string = function DEBUG -> "DBG" | INFO -> "INF" | WARN -> "WAR" | ERROR -> "ERR"
let to_string = function DEBUG -> "DBG" | INFO -> "INF" | WARN -> "WAR" | ERROR -> "ERR" | FATAL -> "EXT"

let to_color = function
| DEBUG -> "\x1b[36m" (* Cyan *)
| INFO -> "\x1b[32m" (* Green *)
| WARN -> "\x1b[33m" (* Yellow *)
| ERROR -> "\x1b[31m" (* Red *)
| FATAL -> "\x1b[31m" (* Red *)
;;

let reset_color = "\x1b[0m"
3 changes: 2 additions & 1 deletion lib/logger/sync.ml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
let log ?m ?f level fmt =
let kprintf_logger str =
let formatted_msg = Base.format_message ?m ?f level str in
Printf.printf "%s" formatted_msg
match level with Level.FATAL -> failwith formatted_msg | _ -> Printf.printf "%s" formatted_msg
in
Printf.ksprintf kprintf_logger fmt
;;
Expand All @@ -10,3 +10,4 @@ let debug ?m ?f fmt = log ?m ?f Level.DEBUG fmt
let info ?m ?f fmt = log ?m ?f Level.INFO fmt
let warn ?m ?f fmt = log ?m ?f Level.WARN fmt
let error ?m ?f fmt = log ?m ?f Level.ERROR fmt
let fatal ?m ?f fmt = log ?m ?f Level.FATAL fmt

0 comments on commit b1619f8

Please sign in to comment.