talircd/bin/main.ml

51 lines
1.2 KiB
OCaml

let min_level =
match Sys.getenv_opt "LOG_LEVEL" |> Option.map String.uppercase_ascii with
| Some "TRACE" -> Logging.TRACE
| Some "DEBUG" -> Logging.TRACE
| Some "INFO" -> Logging.TRACE
| Some ("WARN" | "WARNING") -> Logging.TRACE
| Some ("ERR" | "ERROR") -> Logging.TRACE
| _ -> Logging.INFO
let no_color = Option.is_some (Sys.getenv_opt "LOG_NO_COLOR")
let no_timestamp = Option.is_some (Sys.getenv_opt "LOG_NO_TIMESTAMP")
let no_namespace = Option.is_some (Sys.getenv_opt "LOG_NO_NAMESPACE")
let () =
match Sys.getenv_opt "JOURNAL_STREAM" with
| Some _ ->
Logging.init_journald_writer ()
~min_level
| None ->
Logging.init_pretty_writer stderr
~min_level
~color:(not no_color)
~timestamp:(not no_timestamp)
~namespace:(not no_namespace)
let port =
try
let port = int_of_string (Sys.getenv "IRC_PORT") in
if port <= 0 || port > 65535 then failwith "invalid port";
port
with _ ->
6667
let hostname =
match Sys.getenv_opt "IRC_HOSTNAME" with
| Some x -> x
| None -> "irc.tali.software"
let config : Server.config = {
port;
hostname;
listen_backlog = 8;
ping_interval = 60;
whowas_history_len = 1000;
(* TODO: motd *)
}
let () =
Lwt_main.run @@ Server.run config