<div dir="ltr">On Fri, Oct 10, 2008 at 11:09 AM, Sergey A. <span dir="ltr"><<a href="mailto:n39052@gmail.com" target="_blank">n39052@gmail.com</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

Hello.<br>
<br>
In the first place, sorry for several different questions placed in<br>
one letter. I know it's something wearily to answer a list of<br>
questions.<br>
<br>
I tried using error_logger as a tool for handling error reports and<br>
I've came across some oddities:<br>
<br>
#1. Is there a way to set SASL options (I'm about sasl_error_logger,<br>
errlog_type etc) from the Erlang code at runtime without using a<br>
.config file + the "-config" argument?</blockquote><div><br>Possibly, but I don't know how.<br> <br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
I just want to give an end user<br>
only one config file to edit and use values from that to setup SASL.</blockquote><div> </div><div>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 <a href="http://www.erlang.org/doc/man/systools.html">http://www.erlang.org/doc/man/systools.html</a>).<br>
<br>[<br>    {sasl,<br>        [<br>            {sasl_error_logger, {file, "/data/shg/log_base/shg.sasl_log"}}<br>        ]},<br><br><br>    {myapp1, <br>        [<br>            {myappvar1, "value1"},<br>
            {myappvar2,  value2}<br>        ]<br>    }<br>].   %% <-- dot and whitespace<br><br>Remember to have a dot and whitespace at end of file as shown above.<br><br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

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


<p>The following error logger event handlers are defined in
the SASL application.
</p>
<dl><dt>
<span class="code">sasl_report_tty_h</span>
</dt><dd>

Formats and writes <strong>supervisor reports</strong>, <strong>crash reports</strong> and <strong>progress reports</strong> to <span class="code">stdio</span>.<br>


</dd><dt>
<span class="code">sasl_report_file_h</span>
</dt><dd>

Formats and writes <strong>supervisor reports</strong>, <strong>crash report</strong> and <strong>progress report</strong> to a single file.<br>


</dd><dt>
<span class="code">error_logger_mf_h</span>
</dt><dd>

This error logger writes <strong>all</strong> events sent to
the error logger to disk. It installs the <span class="code">log_mf_h</span>
event handler in the <span class="code">error_logger</span> process.</dd></dl>You need to configure the error_logger_mf_h to get what you have logged, for example:<br> <br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">[</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">    {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">        sasl, [</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">            % All supervisor, crash, and progress reports go to this file</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">            {sasl_error_logger, {file, "/tmp/error_logs/sasl_log" }},</span><br>
<span style="font-family: courier new,monospace;">            % And to these files, too</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">            {error_logger_mf_dir, "/tmp/error_logs"},</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">            {error_logger_mf_maxbytes, 10000000},</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">            {error_logger_mf_maxfiles, 10}</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">        ]</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    }</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">].</span><br style="font-family: courier new,monospace;"><br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
#3. If I decide to use rotating of logs, those logs will be written in<br>
binary format. What are the benefits of using binary format for<br>
storing logs? </blockquote><div><br>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.<br>
 <br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Is there possibility to force Erlang to use plain text<br>
files instead of binary ones?<br>
</blockquote><div><br>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:<br><a href="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/disk_log_h.erl?revision=1.2&view=markup</a><br>
<a href="http://jungerl.cvs.sourceforge.net/viewvc/jungerl/jungerl/lib/msc/src/logger.erl?revision=1.2&view=markup">http://jungerl.cvs.sourceforge.net/viewvc/jungerl/jungerl/lib/msc/src/logger.erl?revision=1.2&view=markup</a><br>
The files contain documentation on how to install and use these. I've used them for quite a while with no problems.<br> <br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
#4. What is the "index" file for?<br>
</blockquote><div>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.<br>
<br>1> file:read_file("index").<br>{ok,<<2>>}<br>2> <br><br>Yes, looks like it's just a binary integer that has the next wrap index.<br> <br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
#5. Quote from Programming Erlang:<br>
--[Beginning of quote]-------------------------------------------------<br>
In a production environment, we are really interested only in errors and<br>
not progress or information reports, so we tell the error logger to report<br>
only errors. Without this setting, the system might get swamped with<br>
information and progress reports.<br>
 Download elog4.config<br>
%% rotating log and errors<br>
[{sasl, [<br>
             %% minimise shell error logging<br>
             {sasl_error_logger, false},<br>
             %% only report errors<br>
             {errlog_type, error},<br>
             %% define the parameters of the rotating log<br>
             %% the log file directory<br>
             {error_logger_mf_dir,"/home/joe/error_logs" },<br>
             %% # bytes per logfile<br>
             {error_logger_mf_maxbytes,10485760}, % 10 MB<br>
             %% maximum number of<br>
             {error_logger_mf_maxfiles, 10}<br>
           ]}].<br>
--[End of quote]-------------------------------------------------<br>
<br>
But using this config I see some progress reports:<br>
<br>
3> rb:list().<br>
  No                Type   Process       Date     Time<br>
  ==                ====   =======       ====     ====<br>
   6            progress  <0.30.0> 2008-10-10 03:39:59<br>
   5            progress  <0.30.0> 2008-10-10 03:39:59<br>
   4            progress  <0.30.0> 2008-10-10 03:39:59<br>
   3            progress  <0.30.0> 2008-10-10 03:39:59<br>
   2            progress  <0.23.0> 2008-10-10 03:39:59<br>
   1               error  <0.24.0> 2008-10-10 03:40:20<br>
ok<br>
<br>
What is wrong?</blockquote><div><br>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.<br>
<br>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.<br>
<br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><font color="#888888">P.S. Sorry for the possible English mistakes in my letter =)</font></blockquote>
<div>Your English is pretty good, actually.<br></div></div>Hope this helps.<br>Edwin<br></div>