-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
361 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
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 | ||
in | ||
Printf.ksprintf ksprintf_logger fmt | ||
;; | ||
|
||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
let get_timestamp () = | ||
let open Unix in | ||
let tm = localtime (time ()) in | ||
Printf.sprintf | ||
"%04d-%02d-%02d %02d:%02d:%02d" | ||
(tm.tm_year + 1900) | ||
(tm.tm_mon + 1) | ||
tm.tm_mday | ||
tm.tm_hour | ||
tm.tm_min | ||
tm.tm_sec | ||
;; | ||
|
||
let format_message ?(m = "") ?(f = "") level msg = | ||
let time_str = get_timestamp () in | ||
let level_str = Level.to_string level in | ||
let color = Level.to_color level in | ||
let reset = Level.reset_color in | ||
let location_str = | ||
match m, f with | ||
| "", "" -> "" | ||
| "", f -> Printf.sprintf "[%s]" f | ||
| m, "" -> Printf.sprintf "[%s]" m | ||
| m, f -> Printf.sprintf "[%s::%s]" m f | ||
in | ||
Printf.sprintf "[%s] [%s%s%s] %s %s\n%!" time_str color level_str reset location_str msg | ||
;; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
type t = | ||
| DEBUG | ||
| INFO | ||
| WARN | ||
| ERROR | ||
|
||
let to_string = function DEBUG -> "DBG" | INFO -> "INF" | WARN -> "WAR" | ERROR -> "ERR" | ||
|
||
let to_color = function | ||
| DEBUG -> "\x1b[36m" (* Cyan *) | ||
| INFO -> "\x1b[32m" (* Green *) | ||
| WARN -> "\x1b[33m" (* Yellow *) | ||
| ERROR -> "\x1b[31m" (* Red *) | ||
;; | ||
|
||
let reset_color = "\x1b[0m" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
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 | ||
in | ||
Printf.ksprintf kprintf_logger fmt | ||
;; | ||
|
||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.