Current section

Files

Jump to
discord_gleam src discord_gleam@logging.erl
Raw

src/discord_gleam@logging.erl

-module(discord_gleam@logging).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([println/2]).
-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,
<<<<Date_without_timezone/binary, " "/utf8>>/binary,
Time_without_timezone/binary>>.
-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@io:println(
<<<<<<<<(get_date_string())/binary, " | "/utf8>>/binary,
Log_splitter/binary>>/binary,
"\x{001b}[0m | "/utf8>>/binary,
Content/binary>>
).