<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">https://gist.github.com/mdjunior/9369937</a></div><div><br></div><div><pre class="" style="font-family:Consolas,'Liberation Mono',Courier,monospace;font-size:12px;line-height:16.799999237060547px;width:744px;margin-top:0px;margin-bottom:0px;padding:0px;color:rgb(0,0,0)">

<div class="" id="file-gistfile1-pl-LC1"><span class="" style="font-weight:bold">sub </span><span class="" style="color:rgb(153,0,0);font-weight:bold">log_wrapper</span> <span class="">{</span></div><div class="" id="file-gistfile1-pl-LC2">

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

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

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

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

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

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

<div class="" id="file-gistfile1-pl-LC11">        <span class="" style="color:rgb(51,51,51)">syslog</span><span class="">(</span> <span class="" style="color:teal">$priority</span><span class="">,</span> <span class="" style="color:teal">$log</span> <span class="">);</span></div>

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

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

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

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

<div class="" id="file-gistfile1-pl-LC17">                                <span class="" style="color:rgb(51,51,51)">Priority</span> <span class="" style="font-weight:bold">=></span> <span class="" style="color:teal">$priority</span><span class="">,</span></div>

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

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

<div class="" id="file-gistfile1-pl-LC20">                                <span class="">);</span></div><div class="" id="file-gistfile1-pl-LC21">        <span class="" style="color:teal">$log_net</span><span class="" style="font-weight:bold">-></span><span class="" style="color:rgb(0,134,179)">send</span><span class="">(</span><span class="" style="color:teal">$log</span><span class="">);</span></div>

<div class="" id="file-gistfile1-pl-LC22">    <span class="">}</span></div><div class="" id="file-gistfile1-pl-LC23">    <span class="" style="font-weight:bold">return</span><span class="">;</span></div><div class="" id="file-gistfile1-pl-LC24">

<span class="">}</span></div><div class="" id="file-gistfile1-pl-LC24"><span class=""><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>