user1418225
user1418225

Reputation:

Ejabberd debugging

I want to make some debugging to a Ejabberd module I am working on; however, as I am working on Windows the best option I have is to do just by logging.

I can't make work the logging. I am using error_logger:warning_msg("here!") however I can't see this in the logs.

I have checked ejabberd.log and error.log.

Any ideas of debugging or logging for ejabberd are welcome. As I have said I am working on Windows.

Update

I changed my code and now looks like this:

start(Host, Opts) ->
    ?DEBUG("Starting: ~p ~p", [Host, Opts]),
    Proc = gen_mod:get_module_proc(Host, ?MODULE),
    ChildSpec = {
        Proc,
        {?MODULE, start_link, [Host, Opts]},
        transient,
        1000,
        worker,
        [?MODULE]
    },
    supervisor:start_child(ejabberd_sup, ChildSpec).

But I am getting this error

2015-09-14 17:01:11.863 [critical] <0.37.0>@gen_mod:start_module:107 Problem starting the module mod_restful for host <<"fernando">> 
 options: [{api,[[{path,[<<"admin">>]},
                  {module,mod_restful_admin},
                  {params,[{key,<<"secret">>},
                           {allowed_commands,[register,unregister]}]}],
                 [{path,[<<"register">>]},
                  {module,mod_restful_register},
                  {params,[{key,<<"secret">>}]}]]}]
 error: undef
[{p1_logger,debug_msg,[mod_restful,80,"Starting: ~p ~p",["fer","fer"]],[]},
 {mod_restful,start,2,
              [{file,"d:/Sites/mod_restful/src/mod_restful.erl"},{line,80}]},
 {gen_mod,start_module,3,[{file,"src/gen_mod.erl"},{line,99}]},
 {lists,foreach,2,[{file,"lists.erl"},{line,1336}]},
 {ejabberd_app,start,2,[{file,"src/ejabberd_app.erl"},{line,72}]},
 {application_master,start_it_old,4,
                     [{file,"application_master.erl"},{line,272}]}]
2015-09-14 17:01:11.863 [critical] <0.37.0>@gen_mod:start_module:112 ejabberd initialization was aborted because a module start failed.

Upvotes: 1

Views: 2575

Answers (3)

Sujan Kumar Sakthi
Sujan Kumar Sakthi

Reputation: 423

You have to include "-include("logger.hrl")." to the top of your module. This only tells that macro definition to ejabberd.

And you can also change the debug levels in run time using "ejabberdctl set_loglevel 4" command.

The log levels are: 0: No ejabberd log
1: Critical
2: Error
3: Warning
4: Info
5: Debug

Upvotes: 0

user1418225
user1418225

Reputation:

Worked fine after adding

-ifndef(LAGER).
-define(LAGER, 1).
-endif.

before including libraries:

-include("ejabberd.hrl").
-include("logger.hrl").
-include("jlib.hrl").

By default debug doesn't work, just info, warning, error and critical

?DEBUG("Starting: ~p ~p", [Host, Opts]),
?INFO_MSG("Starting: ~p ~p", [Host, Opts]),
?WARNING_MSG("Starting: ~p ~p", [Host, Opts]),
?ERROR_MSG("Starting: ~p ~p", [Host, Opts]),
?CRITICAL_MSG("Starting: ~p ~p", [Host, Opts]),

Upvotes: 1

Micka&#235;l R&#233;mond
Micka&#235;l R&#233;mond

Reputation: 9055

I just tried from my local ejabberd install and it appears properly in ejabberd.log file:

2015-09-14 17:30:20.819 [warning] <0.36.0> here!

Please, note however that ejabberd convention is to use macros like the following:

?DEBUG(Format, Args).
?INFO_MSG(Format, Args).
?WARNING_MSG(Format, Args).
?ERROR_MSG(Format, Args).
?CRITICAL_MSG(Format, Args).

It is compliant with several logger backend (like lager) and will be friendly with the error level you set in ejabberd.

Upvotes: 0

Related Questions