Support 'auto' value in log options, set as default
This commit is contained in:
parent
10b1a83bbf
commit
cc4702882f
|
@ -19,10 +19,8 @@
|
|||
-include_lib("xmpp/include/xmpp.hrl").
|
||||
|
||||
-define(PROCNAME, ?MODULE).
|
||||
-define(DEFAULT_PATH, ".").
|
||||
-define(DEFAULT_FORMAT, text).
|
||||
|
||||
-record(config, {path=?DEFAULT_PATH, format=?DEFAULT_FORMAT}).
|
||||
-record(config, {path, format}).
|
||||
|
||||
start(Host, Opts) ->
|
||||
?DEBUG(" ~p ~p~n", [Host, Opts]),
|
||||
|
@ -44,7 +42,12 @@ start_vhs(Host, [{_VHost, _Opts}| Tail]) ->
|
|||
?DEBUG("start_vhs ~p ~p~n", [Host, [{_VHost, _Opts}| Tail]]),
|
||||
start_vhs(Host, Tail).
|
||||
start_vh(Host, Opts) ->
|
||||
Path = gen_mod:get_opt(path, Opts),
|
||||
Path = case gen_mod:get_opt(path, Opts) of
|
||||
auto ->
|
||||
filename:dirname(ejabberd_logger:get_log_path());
|
||||
PP ->
|
||||
PP
|
||||
end,
|
||||
Format = gen_mod:get_opt(format, Opts),
|
||||
ejabberd_hooks:add(user_send_packet, Host, ?MODULE, log_packet_send, 55),
|
||||
ejabberd_hooks:add(user_receive_packet, Host, ?MODULE, log_packet_receive, 55),
|
||||
|
@ -276,13 +279,13 @@ depends(_Host, _Opts) ->
|
|||
[].
|
||||
|
||||
mod_opt_type(host_config) -> econf:list(econf:any());
|
||||
mod_opt_type(path) -> econf:directory(write);
|
||||
mod_opt_type(path) -> econf:either(auto, econf:directory(write));
|
||||
mod_opt_type(format) ->
|
||||
fun (A) when is_atom(A) -> A end.
|
||||
|
||||
mod_options(_Host) ->
|
||||
[{host_config, []},
|
||||
{path, ?DEFAULT_PATH},
|
||||
{format, ?DEFAULT_FORMAT}].
|
||||
{path, auto},
|
||||
{format, text}].
|
||||
|
||||
mod_doc() -> #{}.
|
||||
|
|
|
@ -21,9 +21,11 @@ Note: to log the failed authentication attempts, you need to patch ejabberd.
|
|||
-----------------------
|
||||
|
||||
sessionlog:
|
||||
Define the name of log files.
|
||||
The keyword @HOST@ will be substituted with the name of each vhost.
|
||||
Default value: "/tmp/ejabberd_logsession_@HOST@.log"
|
||||
Define the name of log files, or set to 'auto'.
|
||||
The keyword @HOST@ is substituted with the name of the vhost.
|
||||
If set to 'auto', it will store in the ejabberd log path
|
||||
with the filename "session_@HOST@.log"
|
||||
Default value: auto
|
||||
|
||||
|
||||
EXAMPLE CONFIGURATION
|
||||
|
|
|
@ -49,9 +49,13 @@ start(Host, Opts) ->
|
|||
ejabberd_hooks:add(forbidden_session_hook, Host, ?MODULE, forbidden, 50),
|
||||
ejabberd_hooks:add(c2s_auth_result, Host, ?MODULE, failed_auth, 50),
|
||||
ejabberd_commands:register_commands(commands()),
|
||||
Filename1 = gen_mod:get_opt(
|
||||
sessionlog,
|
||||
Opts),
|
||||
Filename1 = case gen_mod:get_opt(sessionlog, Opts) of
|
||||
auto ->
|
||||
filename:join(filename:dirname(ejabberd_logger:get_log_path()),
|
||||
"session_@HOST@.log");
|
||||
SL ->
|
||||
SL
|
||||
end,
|
||||
Filename = replace_host(Host, Filename1),
|
||||
File = open_file(Filename),
|
||||
register(get_process_name(Host), spawn(?MODULE, loop, [Filename, File, Host])),
|
||||
|
@ -69,10 +73,10 @@ depends(_Host, _Opts) ->
|
|||
[].
|
||||
|
||||
mod_opt_type(sessionlog) ->
|
||||
econf:string().
|
||||
econf:either(auto, econf:string()).
|
||||
|
||||
mod_options(_Host) ->
|
||||
[{sessionlog, "/tmp/ejabberd_logsession_@HOST@.log"}].
|
||||
[{sessionlog, auto}].
|
||||
|
||||
mod_doc() -> #{}.
|
||||
|
||||
|
|
|
@ -32,7 +32,8 @@ orientation:
|
|||
Default value: [send, revc]
|
||||
logdir:
|
||||
Base filename, including absolute path
|
||||
Default value: "/tmp/jabberlogs/"
|
||||
If set to 'auto', it uses the ejabberd log path.
|
||||
Default value: auto
|
||||
show_ip:
|
||||
If the IP address of the local user should be logged to file.
|
||||
Default value: false
|
||||
|
|
|
@ -24,8 +24,10 @@
|
|||
%% -------------------
|
||||
|
||||
start(Host, Opts) ->
|
||||
Logdir = gen_mod:get_opt(logdir, Opts),
|
||||
|
||||
Logdir = case gen_mod:get_opt(logdir, Opts) of
|
||||
auto -> filename:dirname(ejabberd_logger:get_log_path());
|
||||
LD -> LD
|
||||
end,
|
||||
Rd = case gen_mod:get_opt(rotate_days, Opts) of
|
||||
0 -> no;
|
||||
Rd1 -> Rd1
|
||||
|
@ -278,7 +280,7 @@ mod_opt_type(direction) ->
|
|||
mod_opt_type(orientation) ->
|
||||
econf:list(econf:enum([send, recv]));
|
||||
mod_opt_type(logdir) ->
|
||||
econf:directory();
|
||||
econf:either(auto, econf:directory(write));
|
||||
mod_opt_type(show_ip) ->
|
||||
econf:bool();
|
||||
mod_opt_type(rotate_days) ->
|
||||
|
@ -294,7 +296,7 @@ mod_options(_Host) ->
|
|||
[{stanza, [iq, message, presence, other]},
|
||||
{direction, [internal, vhosts, external]},
|
||||
{orientation, [send, recv]},
|
||||
{logdir, "/tmp/jabberlogs/"},
|
||||
{logdir, auto},
|
||||
{show_ip, false},
|
||||
{rotate_days, 1},
|
||||
{rotate_megs, 10},
|
||||
|
|
|
@ -28,3 +28,7 @@ of your ejabberd.yml file:
|
|||
|
||||
mod_message_log:
|
||||
filename: "/path/to/ejabberd-message.log"
|
||||
|
||||
If the filename option is set to 'auto', it will be set to
|
||||
the default ejabberd log path, with the file name "message.log".
|
||||
The filename option takes as default value 'auto'.
|
||||
|
|
|
@ -53,10 +53,9 @@
|
|||
|
||||
-include_lib("xmpp/include/xmpp.hrl").
|
||||
|
||||
-define(DEFAULT_FILENAME, <<"message.log">>).
|
||||
-define(FILE_MODES, [append, raw]).
|
||||
|
||||
-record(state, {filename = ?DEFAULT_FILENAME :: binary(),
|
||||
-record(state, {filename :: binary(),
|
||||
iodevice :: io:device()}).
|
||||
|
||||
-type direction() :: incoming | outgoing | offline.
|
||||
|
@ -97,11 +96,11 @@ stop(Host) ->
|
|||
|
||||
-spec mod_opt_type(atom()) -> fun((term()) -> term()).
|
||||
mod_opt_type(filename) ->
|
||||
fun iolist_to_binary/1.
|
||||
econf:either(auto, econf:file(write)).
|
||||
|
||||
-spec mod_options(binary()) -> [{atom(), any()}].
|
||||
mod_options(_Host) ->
|
||||
[{filename, ?DEFAULT_FILENAME}].
|
||||
[{filename, auto}].
|
||||
|
||||
-spec depends(binary(), gen_mod:opts()) -> [{module(), hard | soft}].
|
||||
depends(_Host, _Opts) ->
|
||||
|
@ -116,7 +115,12 @@ mod_doc() -> #{}.
|
|||
init([_Host, Opts]) ->
|
||||
process_flag(trap_exit, true),
|
||||
ejabberd_hooks:add(reopen_log_hook, ?MODULE, reopen_log, 42),
|
||||
Filename = gen_mod:get_opt(filename, Opts),
|
||||
Filename = case gen_mod:get_opt(filename, Opts) of
|
||||
auto ->
|
||||
filename:join(filename:dirname(ejabberd_logger:get_log_path()),
|
||||
"message.log");
|
||||
FN -> FN
|
||||
end,
|
||||
{ok, IoDevice} = file:open(Filename, ?FILE_MODES),
|
||||
{ok, #state{filename = Filename, iodevice = IoDevice}}.
|
||||
|
||||
|
|
|
@ -24,10 +24,10 @@ on mod_muc_log.
|
|||
|
||||
listen:
|
||||
-
|
||||
port: 5280
|
||||
port: 5282
|
||||
module: ejabberd_http
|
||||
request_handlers:
|
||||
"/pub/muclogs": mod_muc_log_http
|
||||
/muclogs: mod_muc_log_http
|
||||
|
||||
modules:
|
||||
mod_muc_log:
|
||||
|
@ -39,4 +39,4 @@ modules:
|
|||
=====
|
||||
|
||||
With the example options, open your web browser at:
|
||||
http://server:5280/pub/muclogs/
|
||||
http://server:5282/muclogs/
|
||||
|
|
|
@ -32,7 +32,7 @@ listen:
|
|||
port: 5285
|
||||
module: ejabberd_http
|
||||
request_handlers:
|
||||
"/rest": mod_rest
|
||||
/rest: mod_rest
|
||||
|
||||
With that configuration, you can send HTTP POST requests to the URL:
|
||||
http://localhost:5285/rest
|
||||
|
|
|
@ -43,27 +43,25 @@
|
|||
-include("logger.hrl").
|
||||
|
||||
-define(PROCNAME, ?MODULE).
|
||||
-define(DEFAULT_FILENAME, <<"s2s.log">>).
|
||||
-define(FILE_OPTS, [append,raw]).
|
||||
|
||||
-record(config, {filename=?DEFAULT_FILENAME, iodevice}).
|
||||
-record(config, {filename, iodevice}).
|
||||
|
||||
%% For now we only support one log file for all vhosts.
|
||||
start(Host, Opts) ->
|
||||
case whereis(?PROCNAME) of
|
||||
undefined ->
|
||||
Filename = gen_mod:get_opt(filename, Opts),
|
||||
case filelib:ensure_dir(Filename) of
|
||||
ok ->
|
||||
FilenameStr = case gen_mod:get_opt(filename, Opts) of
|
||||
auto ->
|
||||
filename:join(filename:dirname(ejabberd_logger:get_log_path()),
|
||||
"s2s.log");
|
||||
FN -> FN
|
||||
end,
|
||||
Filename = list_to_binary(FilenameStr),
|
||||
register(?PROCNAME,
|
||||
spawn(?MODULE, init, [#config{filename=Filename}])),
|
||||
ejabberd_hooks:add(reopen_log_hook, ?MODULE, reopen_log, 55),
|
||||
s2s_hooks(Host, add);
|
||||
{error, Why} = Err ->
|
||||
?ERROR_MSG("failed to create directories along the path ~s: ~s",
|
||||
[Filename, file:format_error(Why)]),
|
||||
Err
|
||||
end;
|
||||
_ ->
|
||||
s2s_hooks(Host, add)
|
||||
end.
|
||||
|
@ -115,10 +113,10 @@ depends(_, _) ->
|
|||
[].
|
||||
|
||||
mod_opt_type(filename) ->
|
||||
fun iolist_to_binary/1.
|
||||
econf:either(auto, econf:file(write)).
|
||||
|
||||
mod_options(_Host) ->
|
||||
[{filename, ?DEFAULT_FILENAME}].
|
||||
[{filename, auto}].
|
||||
|
||||
mod_doc() -> #{}.
|
||||
|
||||
|
|
|
@ -44,7 +44,6 @@
|
|||
%% Copied from ejabberd_sm.erl
|
||||
-record(session, {sid, usr, us, priority, info}).
|
||||
|
||||
-define(PIXMAPS_DIR, <<"pixmaps">>).
|
||||
-define(AUTO_ACL, webpresence_auto).
|
||||
|
||||
%%====================================================================
|
||||
|
@ -54,7 +53,13 @@ start_link() ->
|
|||
gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
|
||||
|
||||
start(Host, Opts) ->
|
||||
Dir = gen_mod:get_opt(pixmaps_path, Opts),
|
||||
Dir = case gen_mod:get_opt(pixmaps_path, Opts) of
|
||||
auto ->
|
||||
Package = atom_to_list(?MODULE),
|
||||
filename:join([ext_mod:modules_dir(), Package, "priv", "pixmaps"]);
|
||||
PP ->
|
||||
PP
|
||||
end,
|
||||
catch ets:new(pixmaps_dirs, [named_table, public]),
|
||||
ets:insert(pixmaps_dirs, {directory, Dir}),
|
||||
case gen_mod:start_child(?MODULE, Host, Opts) of
|
||||
|
@ -77,7 +82,7 @@ mod_opt_type(host) ->
|
|||
mod_opt_type(access) ->
|
||||
econf:acl();
|
||||
mod_opt_type(pixmaps_path) ->
|
||||
econf:directory();
|
||||
econf:either(auto, econf:directory());
|
||||
mod_opt_type(port) ->
|
||||
econf:pos_int();
|
||||
mod_opt_type(path) ->
|
||||
|
@ -89,7 +94,7 @@ mod_opt_type(baseurl) ->
|
|||
mod_options(Host) ->
|
||||
[{host, <<"webpresence.", Host/binary>>},
|
||||
{access, local},
|
||||
{pixmaps_path, ?PIXMAPS_DIR},
|
||||
{pixmaps_path, auto},
|
||||
{port, 5280},
|
||||
{path, <<"presence">>},
|
||||
{baseurl, iolist_to_binary(io_lib:format(<<"http://~s:5280/presence/">>, [Host]))}].
|
||||
|
|
Loading…
Reference in New Issue