25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-26 16:26:24 +01:00

Use records for encoding static loglevel information.

This commit is contained in:
Andreas Köhler 2010-10-12 14:41:21 +02:00 committed by Badlop
parent d1f5fb4aa9
commit 61d8bf9440

View File

@ -38,19 +38,25 @@
-define(LOGMODULE, "error_logger"). -define(LOGMODULE, "error_logger").
%% Error levels: %% Error levels:
-define(LOG_LEVELS,[ {0, no_log, "No log"} -record(loglevel, {ordinal,
,{1, critical, "Critical"} name,
,{2, error, "Error"} description}).
,{3, warning, "Warning"}
,{4, info, "Info"} -define(LOG_LEVELS,
,{5, debug, "Debug"} [#loglevel{ordinal = 0, name = no_log, description = "No log"},
]). #loglevel{ordinal = 1, name = critical, description = "Critical"},
#loglevel{ordinal = 2, name = error, description = "Error"},
#loglevel{ordinal = 3, name = warning, description = "Warning"},
#loglevel{ordinal = 4, name = info, description = "Info"},
#loglevel{ordinal = 5, name = debug, description = "Debug"}]).
get() -> get() ->
Level = ejabberd_logger:get(), Level = ejabberd_logger:get(),
case lists:keysearch(Level, 1, ?LOG_LEVELS) of case lists:keysearch(Level, #loglevel.ordinal, ?LOG_LEVELS) of
{value, Result} -> Result; {value, Result = #loglevel{}} ->
_ -> erlang:error({no_such_loglevel, Level}) {Result#loglevel.ordinal, Result#loglevel.name, Result#loglevel.description};
_ ->
erlang:error({no_such_loglevel, Level})
end. end.
@ -67,8 +73,8 @@ set(_) ->
exit("Loglevel must be an integer"). exit("Loglevel must be an integer").
level_to_integer(Level) -> level_to_integer(Level) ->
case lists:keysearch(Level, 2, ?LOG_LEVELS) of case lists:keysearch(Level, #loglevel.name, ?LOG_LEVELS) of
{value, {Int, Level, _Desc}} -> Int; {value, #loglevel{ordinal = Int}} -> Int;
_ -> erlang:error({no_such_loglevel, Level}) _ -> erlang:error({no_such_loglevel, Level})
end. end.