[erlang-questions] Lots of questions about error_logger

Edwin Fine erlang-questions_efine@REDACTED
Sat Oct 11 21:13:06 CEST 2008


On Fri, Oct 10, 2008 at 11:09 AM, Sergey A. <n39052@REDACTED> wrote:

> Hello.
>
> In the first place, sorry for several different questions placed in
> one letter. I know it's something wearily to answer a list of
> questions.
>
> I tried using error_logger as a tool for handling error reports and
> I've came across some oddities:
>
> #1. Is there a way to set SASL options (I'm about sasl_error_logger,
> errlog_type etc) from the Erlang code at runtime without using a
> .config file + the "-config" argument?


Possibly, but I don't know how.

I just want to give an end user
> only one config file to edit and use values from that to setup SASL.


You can put the sasl config along with other application configs. You can
pass application environment variables in this way to your own apps. This
usually goes into a file named sys.config, which is expected (or at least
standard) if you use Erlang release management (see
http://www.erlang.org/doc/man/systools.html).

[
    {sasl,
        [
            {sasl_error_logger, {file, "/data/shg/log_base/shg.sasl_log"}}
        ]},


    {myapp1,
        [
            {myappvar1, "value1"},
            {myappvar2,  value2}
        ]
    }
].   %% <-- dot and whitespace

Remember to have a dot and whitespace at end of file as shown above.


> #2. The following is from the "Programming Erlang":
>
> --[Beginning of quote]-------------------------------------------------
> The next configuration file lists error reports in the shell, and a copy of
> everything reported in the shell is also made to a file:
>
> %% single text file - minimal tty
> [{sasl, [
>             %% All reports go to this file
>             {sasl_error_logger, {file, "/home/joe/error_logs/THELOG" }}
>           ]}]."
> --[End of quote]-------------------------------------------------
>
> I replaced the path to just "THELOG" and then run the shell:
>
> --[Beginning of erl
> session]-------------------------------------------------
> erl -boot start_sasl -config elog2.config
>
> Erlang (BEAM) emulator version 5.6.3 [source] [smp:2]
> [async-threads:0] [hipe] [kernel-poll:false]
>
> Eshell V5.6.3  (abort with ^G)
> 1> error_logger:error_msg("foobar~n").
> ok
>
> =ERROR REPORT==== 10-Oct-2008::03:19:38 ===
> foobar
> 2> error_logger:error_report("foobar\n").
>
> =ERROR REPORT==== 10-Oct-2008::03:21:05 ===
> foobar
>
> ok
> 3>
> User switch command
>  --> q
> --[End of erl session]-------------------------------------------------
>
> But after all, THELOG doesn't contain any string related to my
> foobar-errors! Just only progress reports! Why does this happen?
>

The standard error log handler in SASL only logs supervisor reports, crashes
and progress reports. Take a look at
http://www.erlang.org/doc/apps/sasl/index.html, from which the following was
extracted:
Error Logger Event Handlers

The following error logger event handlers are defined in the SASL
application.
 sasl_report_tty_h Formats and writes *supervisor reports*, *crash reports*and
*progress reports* to stdio.
 sasl_report_file_h Formats and writes *supervisor reports*, *crash report*and
*progress report* to a single file.
 error_logger_mf_h This error logger writes *all* events sent to the error
logger to disk. It installs the log_mf_h event handler in the
error_loggerprocess.You
need to configure the error_logger_mf_h to get what you have logged, for
example:

[
    {
        sasl, [
            % All supervisor, crash, and progress reports go to this file
            {sasl_error_logger, {file, "/tmp/error_logs/sasl_log" }},
            % And to these files, too
            {error_logger_mf_dir, "/tmp/error_logs"},
            {error_logger_mf_maxbytes, 10000000},
            {error_logger_mf_maxfiles, 10}
        ]
    }
].


> #3. If I decide to use rotating of logs, those logs will be written in
> binary format. What are the benefits of using binary format for
> storing logs?


The binary format files are very fast to write and more compact than ASCII
logs. However, they are much less convenient to browse. I think many people
use ASCII logs, but you have to be careful and not flood your system with
logs.


> Is there possibility to force Erlang to use plain text
> files instead of binary ones?
>

Yes, but you have to provide your own error logger callback module.
Fortunately, there is at least one I know of that is publicly available, in
Jungerl. You'll need to get these:
http://jungerl.cvs.sourceforge.net/viewvc/jungerl/jungerl/lib/msc/src/disk_log_h.erl?revision=1.2&view=markup
http://jungerl.cvs.sourceforge.net/viewvc/jungerl/jungerl/lib/msc/src/logger.erl?revision=1.2&view=markup
The files contain documentation on how to install and use these. I've used
them for quite a while with no problems.


>
> #4. What is the "index" file for?
>
I dunno. I think it's for the wrap logs, to ell the logger which number to
use next. So if you are running 10 logs, they start off at 1. Once they get
to 10, they start at 1 again. I think the index file contains the next
index. Let's find out.

1> file:read_file("index").
{ok,<<2>>}
2>

Yes, looks like it's just a binary integer that has the next wrap index.


>
> #5. Quote from Programming Erlang:
> --[Beginning of quote]-------------------------------------------------
> In a production environment, we are really interested only in errors and
> not progress or information reports, so we tell the error logger to report
> only errors. Without this setting, the system might get swamped with
> information and progress reports.
>  Download elog4.config
> %% rotating log and errors
> [{sasl, [
>             %% minimise shell error logging
>             {sasl_error_logger, false},
>             %% only report errors
>             {errlog_type, error},
>             %% define the parameters of the rotating log
>             %% the log file directory
>             {error_logger_mf_dir,"/home/joe/error_logs" },
>             %% # bytes per logfile
>             {error_logger_mf_maxbytes,10485760}, % 10 MB
>             %% maximum number of
>             {error_logger_mf_maxfiles, 10}
>           ]}].
> --[End of quote]-------------------------------------------------
>
> But using this config I see some progress reports:
>
> 3> rb:list().
>  No                Type   Process       Date     Time
>  ==                ====   =======       ====     ====
>   6            progress  <0.30.0> 2008-10-10 03:39:59
>   5            progress  <0.30.0> 2008-10-10 03:39:59
>   4            progress  <0.30.0> 2008-10-10 03:39:59
>   3            progress  <0.30.0> 2008-10-10 03:39:59
>   2            progress  <0.23.0> 2008-10-10 03:39:59
>   1               error  <0.24.0> 2008-10-10 03:40:20
> ok
>
> What is wrong?


When you put in {sasl_error_logger, false}, the {errlog_type, error} is
ignored because it pertains only to the sasl_error_logger file. If
{sasl_error_logger, {file, "foo.bar"}} was specified, then {errlog_type,
error} would mean, "Put only errors into foo.bar". It has no control over
what goes into the error_logger_mf binary files.

It appears (AFAIK) that SASL will always log progress reports and crash
reports to the binary file(s) controlled by error_logger_mf, if they are
configured, but because you specified {sasl_error_logger, false} they are
not being duplicated into a separate SASL ASCII log  file, e.g. "foo.bar".
Hope this makes sense.

P.S. Sorry for the possible English mistakes in my letter =)

Your English is pretty good, actually.
Hope this helps.
Edwin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20081011/a6ea3b21/attachment.htm>


More information about the erlang-questions mailing list