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:
parent
a5230c46c2
commit
d1c1902687
@ -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.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user