Skip to content

Commit

Permalink
Add log.startup.
Browse files Browse the repository at this point in the history
  • Loading branch information
smimram committed Jun 1, 2023
1 parent 9ddd8c0 commit bc78544
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ New:
- Added `"metadata_url"` to the default list of exported metadata (#2946)
- Added log colors!
- Added `list.filter_map`.
- Added `log.startup`.

Changed:

Expand Down
18 changes: 17 additions & 1 deletion src/core/builtins/builtins_sys.ml
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ let _ =
Lang.add_builtin ~base:Modules.process "pid" ~category:`System [] Lang.int_t
~descr:"Get the process' pid." (fun _ -> Lang.int (Unix.getpid ()))

let _ =
let log_module =
Lang.add_builtin "log" ~category:`Liquidsoap ~descr:"Log a message."
[
("label", Lang.string_t, Some (Lang.string "lang"), None);
Expand All @@ -286,6 +286,22 @@ let _ =
(Log.make [label])#f level "%s" msg;
Lang.unit)

let _ =
Lang.add_builtin ~base:log_module "startup" ~category:`Liquidsoap
~descr:
"Log a startup message. Unless this function is used, log messages \
emitted at startup are discarded."
[
("label", Lang.string_t, Some (Lang.string "lang"), None);
("", Lang.string_t, None, None);
]
Lang.unit_t
(fun p ->
let msg = List.assoc "" p |> Lang.to_string in
let label = List.assoc "label" p |> Lang.to_string in
Startup.message "%s: %s" label msg;
Lang.unit)

let _ =
(* Cheap implementation of "getopt" which does not really deserve its name
* since it has little to do with the standards that getopt(3) implements.
Expand Down

0 comments on commit bc78544

Please sign in to comment.