-module(discord_gleam@logger). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). -export([println/2]). -if(?OTP_RELEASE >= 27). -define(MODULEDOC(Str), -moduledoc(Str)). -define(DOC(Str), -doc(Str)). -else. -define(MODULEDOC(Str), -compile([])). -define(DOC(Str), -compile([])). -endif. -file("src/discord_gleam/logger.gleam", 6). -spec get_date_string() -> binary(). get_date_string() -> Now = birl:now(), Date_string_with_timezone = birl:to_date_string(Now), Time_string_with_timezone = birl:to_time_string(Now), Date_parts = gleam@string:split(Date_string_with_timezone, <<"+"/utf8>>), Date_without_timezone = case gleam@list:first(Date_parts) of {ok, Value} -> Value; {error, _} -> Date_string_with_timezone end, Time_parts = gleam@string:split(Time_string_with_timezone, <<"+"/utf8>>), Time_without_timezone = case gleam@list:first(Time_parts) of {ok, Value@1} -> Value@1; {error, _} -> Date_string_with_timezone end, <<<>/binary, Time_without_timezone/binary>>. -file("src/discord_gleam/logger.gleam", 31). ?DOC( " Logging types: log (default), info, warn, error\n" " Prints like this: 2024-01-01 12:00:00 | LOG_TYPE | Content\n" " Example: println(\"Hello, world!\", \"info\")\n" ). -spec println(binary(), binary()) -> nil. println(Content, Log_type) -> Log_splitter = case Log_type of <<"info"/utf8>> -> <<"\x{001b}[34mINFO"/utf8>>; <<"warn"/utf8>> -> <<"\x{001b}[33mWARN"/utf8>>; <<"error"/utf8>> -> <<"\x{001b}[31mERROR"/utf8>>; _ -> <<"\x{001b}[32mLOG"/utf8>> end, gleam_stdlib:println( <<<<<<<<(get_date_string())/binary, " | "/utf8>>/binary, Log_splitter/binary>>/binary, "\x{001b}[0m | "/utf8>>/binary, Content/binary>> ).