<a href="http://mojolicio.us/perldoc/Mojo/Log">http://mojolicio.us/perldoc/Mojo/Log</a><br><br>среда, 5 марта 2014 г. пользователь Manoel Domingues Junior  написал:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr">Olá pessoal,<div><br></div><div>Estou fazendo uns scripts(na verdade é uma API com Mojolicious::Lite) aqui e implementei uma função de log usando um conjunto de Net::Syslog com Sys::Syslog para fazer o log do script.</div>


<div><br></div><div><a href="https://gist.github.com/mdjunior/9369937" target="_blank">https://gist.github.com/mdjunior/9369937</a></div><div><br></div><div><pre style="line-height:16.799999237060547px;width:744px;font-size:12px;margin-bottom:0px;font-family:Consolas,'Liberation Mono',Courier,monospace;margin-top:0px;padding:0px">

<div><span style="font-weight:bold">sub </span><span style="color:rgb(153,0,0);font-weight:bold">log_wrapper</span> <span>{</span></div><div>

    <span style="font-weight:bold">my</span> <span style="color:teal">$log</span> <span style="font-weight:bold">=</span> <span style="color:rgb(0,134,179)">shift</span><span>;</span></div>

<div>    <span style="font-weight:bold">my</span> <span style="color:teal">$priority</span> <span style="font-weight:bold">=</span> <span style="color:rgb(0,134,179)">shift</span><span>;</span></div>

<div> </div><div><span style="font-weight:bold"><span style="font-weight:normal">    </span>if</span> <span>(</span> <span style="font-weight:bold">!</span> <span style="color:rgb(0,134,179)">defined</span> <span style="color:teal">$priority</span> <span>)</span> <span>{</span></div>


<div>     <span style="color:teal">$priority</span> <span style="font-weight:bold">=</span> <span style="color:rgb(221,17,68)">'debug'</span><span>;</span></div>

<div><span>    }</span></div><div> </div><div>    <span style="font-weight:bold">if</span> <span>(</span> <span style="color:teal">$ENV</span><span>{</span><span style="color:rgb(51,51,51)">APP_LOG</span><span>}</span> <span style="font-weight:bold">eq</span> <span style="color:rgb(221,17,68)">'LOCAL'</span> <span>)</span> <span>{</span></div>


<div>        <span style="color:rgb(51,51,51)">openlog</span><span>(</span> <span style="color:teal">$ENV</span><span>{</span><span style="color:rgb(51,51,51)">APP_NAME</span><span>}</span><span>,</span> <span style="color:rgb(221,17,68)">'ndelay,pid'</span><span>,</span> <span style="color:rgb(221,17,68)">'LOG_DAEMON'</span> <span>);</span></div>


<div>        <span style="color:rgb(51,51,51)">syslog</span><span>(</span> <span style="color:teal">$priority</span><span>,</span> <span style="color:teal">$log</span> <span>);</span></div>

<div>        <span style="color:rgb(51,51,51)">closelog</span><span>();</span></div><div>    <span>}</span> <span style="font-weight:bold">elsif</span> <span>(</span><span style="color:teal">$ENV</span><span>{</span><span style="color:rgb(51,51,51)">APP_LOG</span><span>}</span> <span style="font-weight:bold">eq</span> <span style="color:rgb(221,17,68)">'NET'</span><span>)</span> <span>{</span></div>


<div>        <span style="font-weight:bold">my</span> <span style="color:teal">$log_net</span> <span style="font-weight:bold">=</span> <span style="color:rgb(85,85,85)">Net::</span><span style="color:rgb(51,51,51)">Syslog</span><span style="font-weight:bold">-></span><span style="font-weight:bold">new</span><span>(</span></div>


<div>                                <span style="color:rgb(51,51,51)">Name</span> <span style="font-weight:bold">=></span> <span style="color:teal">$ENV</span><span>{</span><span style="color:rgb(51,51,51)">APP_NAME</span><span>},</span></div>


<div>                                <span style="color:rgb(51,51,51)">Facility</span> <span style="font-weight:bold">=></span> <span style="color:rgb(221,17,68)">'local7'</span><span>,</span></div>

<div>                                <span style="color:rgb(51,51,51)">Priority</span> <span style="font-weight:bold">=></span> <span style="color:teal">$priority</span><span>,</span></div>

<div>                                <span style="color:rgb(51,51,51)">SyslogPort</span> <span style="font-weight:bold">=></span> <span style="color:teal">$ENV</span><span>{</span><span style="color:rgb(51,51,51)">APP_SYSLOG_PORT</span><span>},</span></div>


<div>                                <span style="color:rgb(51,51,51)">SyslogHost</span> <span style="font-weight:bold">=></span> <span style="color:teal">$ENV</span><span>{</span><span style="color:rgb(51,51,51)">APP_SYSLOG_HOST</span><span>},</span></div>


<div>                                <span>);</span></div><div>        <span style="color:teal">$log_net</span><span style="font-weight:bold">-></span><span style="color:rgb(0,134,179)">send</span><span>(</span><span style="color:teal">$log</span><span>);</span></div>


<div>    <span>}</span></div><div>    <span style="font-weight:bold">return</span><span>;</span></div><div>

<span>}</span></div><div><span><br></span></div></pre></div><div>Pesquisando na internet vi que muita gente comenta sobre o Log::Log4perl e o Log::Any mas não sei bem qual desses (ou outros) é o ideal ou o padrão de uso.</div>


<div><br></div><div>No caso, toda a configuração do meu script fica em variáveis de ambiente. O script possui uma trilha de auditoria que é feita usando os logs, logo ele gera eventos em grande quantidade em diferentes níveis (debug, info e error).</div>


<div><br></div><div>Alguma recomendação?</div><div><br clear="all"><div>Abraços,</div>-- <br>--<br>Manoel Domingues Junior<br>"Coletar dados é o primeiro passo para a sabedoria, mas compartilhar dados é o primeiro passo para a comunidade."<br>


IBM - Prodigy Linux<br>
</div></div>
</blockquote>