From e1f5fb798c15a4022492f1ddb7a4c96dec70f281 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20K=C3=B6hler?= Date: Wed, 13 Oct 2010 14:04:48 +0200 Subject: [PATCH] Add set_custom/2, clear_custom/0 and clear_custom/1 to ejabberd_loglevel --- src/ejabberd_loglevel.erl | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/ejabberd_loglevel.erl b/src/ejabberd_loglevel.erl index 8087dec2a..8f55ed09e 100644 --- a/src/ejabberd_loglevel.erl +++ b/src/ejabberd_loglevel.erl @@ -31,7 +31,11 @@ -module(ejabberd_loglevel). -author('mickael.remond@process-one.net'). --export([set/1, get/0]). +-export([set/1, + get/0, + set_custom/2, + clear_custom/0, + clear_custom/1]). -include("ejabberd.hrl"). @@ -82,6 +86,30 @@ set({DefaultLevel, CustomLevels}) when is_list(CustomLevels) -> set(_) -> exit("Invalid loglevel format"). +set_custom(Module, Level) -> + {DefaultLevel, CustomLevels} = ejabberd_logger:get(), + case lists:keysearch(Module, 1, CustomLevels) of + {value, {Module, Level}} -> + ok; + {value, _} -> + set({DefaultLevel, lists:keyreplace(Module, 1, CustomLevels, {Module, Level})}); + _ -> + set({DefaultLevel, [{Module, Level} | CustomLevels]}) + end. + +clear_custom() -> + {DefaultLevel, CustomLevels} = ejabberd_logger:get(), + set({DefaultLevel, []}). + +clear_custom(Module) -> + {DefaultLevel, CustomLevels} = ejabberd_logger:get(), + case lists:keysearch(Module, 1, CustomLevels) of + {value, _} -> + set({DefaultLevel, lists:keydelete(Module, 1, CustomLevels)}); + _ -> + ok + end. + level_to_integer(Level) when is_integer(Level) -> Level; level_to_integer({Module, Level}) ->