<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/book.seaslog.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'pt_BR',
  ),
  'this' => 
  array (
    0 => 'seaslog.examples.php',
    1 => 'Exemplos',
    2 => 'Exemplos',
  ),
  'up' => 
  array (
    0 => 'book.seaslog.php',
    1 => 'Seaslog',
  ),
  'prev' => 
  array (
    0 => 'seaslog.constants.php',
    1 => 'Constantes predefinidas',
  ),
  'next' => 
  array (
    0 => 'ref.seaslog.php',
    1 => 'Fun&ccedil;&otilde;es de Seaslog',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'pt_BR',
    'path' => 'reference/seaslog/examples.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="seaslog.examples" class="chapter">
 <h1 class="title">Exemplos</h1>


 <div class="example" id="example-1">
  <p><strong>Exemplo #1 Obtendo e definindo o caminho base</strong></p>
  <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$basePath1 </span><span style="color: #007700">= </span><span style="color: #0000BB">SeasLog</span><span style="color: #007700">::</span><span style="color: #0000BB">getBasePath</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">SeasLog</span><span style="color: #007700">::</span><span style="color: #0000BB">setBasePath</span><span style="color: #007700">(</span><span style="color: #DD0000">'/log/base_test'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$basePath2 </span><span style="color: #007700">= </span><span style="color: #0000BB">SeasLog</span><span style="color: #007700">::</span><span style="color: #0000BB">getBasePath</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$basePath1</span><span style="color: #007700">,</span><span style="color: #0000BB">$basePath2</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
  </div>

  <div class="example-contents"><p>O exemplo acima produzirá
algo semelhante a:</p></div>
  <div class="example-contents screen">
<div class="cdata"><pre>
string(12) &quot;/var/log/www&quot;
string(14) &quot;/log/base_test&quot;
</pre></div>
  </div>
 </div>

 <div class="example" id="example-2">
  <p><strong>Exemplo #2 Obtendo e definindo o registrador</strong></p>
  <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$lastLogger1 </span><span style="color: #007700">= </span><span style="color: #0000BB">SeasLog</span><span style="color: #007700">::</span><span style="color: #0000BB">getLastLogger</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">SeasLog</span><span style="color: #007700">::</span><span style="color: #0000BB">setLogger</span><span style="color: #007700">(</span><span style="color: #DD0000">'testModule/app1'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$lastLogger2 </span><span style="color: #007700">= </span><span style="color: #0000BB">SeasLog</span><span style="color: #007700">::</span><span style="color: #0000BB">getLastLogger</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$lastLogger1</span><span style="color: #007700">,</span><span style="color: #0000BB">$lastLogger2</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
  </div>

  <div class="example-contents"><p>O exemplo acima produzirá
algo semelhante a:</p></div>
  <div class="example-contents screen">
<div class="cdata"><pre>
string(7) &quot;default&quot;
string(15) &quot;testModule/app1&quot;
</pre></div>
  </div>
 </div>

 <div class="example" id="example-3">
  <p><strong>Exemplo #3 Registro de gravação rápida</strong></p>
  <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />SeasLog</span><span style="color: #007700">::</span><span style="color: #0000BB">log</span><span style="color: #007700">(</span><span style="color: #0000BB">SEASLOG_ERROR</span><span style="color: #007700">,</span><span style="color: #DD0000">'este é um teste de erro gerado por ::log'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">SeasLog</span><span style="color: #007700">::</span><span style="color: #0000BB">debug</span><span style="color: #007700">(</span><span style="color: #DD0000">'esta é uma informação de depuração criada por {userName}'</span><span style="color: #007700">,array(</span><span style="color: #DD0000">'{userName}' </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">'maria'</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">SeasLog</span><span style="color: #007700">::</span><span style="color: #0000BB">info</span><span style="color: #007700">(</span><span style="color: #DD0000">'este é um registro de informação'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">SeasLog</span><span style="color: #007700">::</span><span style="color: #0000BB">notice</span><span style="color: #007700">(</span><span style="color: #DD0000">'este é um registro de nota'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">SeasLog</span><span style="color: #007700">::</span><span style="color: #0000BB">warning</span><span style="color: #007700">(</span><span style="color: #DD0000">'seu {website} estava indisponível, favor {action} o quanto antes!'</span><span style="color: #007700">,array(</span><span style="color: #DD0000">'{website}' </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">'github.com'</span><span style="color: #007700">,</span><span style="color: #DD0000">'{action}' </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">'reiniciar'</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">SeasLog</span><span style="color: #007700">::</span><span style="color: #0000BB">error</span><span style="color: #007700">(</span><span style="color: #DD0000">'um registro de erro'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">SeasLog</span><span style="color: #007700">::</span><span style="color: #0000BB">critical</span><span style="color: #007700">(</span><span style="color: #DD0000">'alguma coisa crítica ocorreu'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">SeasLog</span><span style="color: #007700">::</span><span style="color: #0000BB">alert</span><span style="color: #007700">(</span><span style="color: #DD0000">'Sim, esta é uma {messageName}'</span><span style="color: #007700">,array(</span><span style="color: #DD0000">'{messageName}' </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">'mensagem_de_alerta'</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">SeasLog</span><span style="color: #007700">::</span><span style="color: #0000BB">emergency</span><span style="color: #007700">(</span><span style="color: #DD0000">'Acontecendo agora, a casa ao lado está completamente em chamas! {note}'</span><span style="color: #007700">,array(</span><span style="color: #DD0000">'{note}' </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">'É brincadeira!'</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
  </div>

  <div class="example-contents"><p>
   Como padrão, <em>seaslog.default_template = &quot;%T | %L | %P | %Q | %t | %M&quot;</em>.
   Isso significa que, como padrão, o estilo de registro é: `{dateTime} | {level} | {pid} | {uniqid} | {timeStamp} | {logInfo}`.
  </p></div>
  <div class="example-contents"><p>O exemplo acima produzirá
algo semelhante a:</p></div>
  <div class="example-contents"><p>
   <em>seaslog.appender = 1</em>
  </p></div>
  <div class="example-contents screen">
<div class="cdata"><pre>
2014-07-27 08:53:52 | ERROR | 23625 | 599159975a9ff | 1406422432.786 | este é um teste de erro gerado por log
2014-07-27 08:53:52 | DEBUG | 23625 | 599159975a9ff | 1406422432.786 | esta é uma informação de depuração criada por maria
2014-07-27 08:53:52 | INFO | 23625 | 599159975a9ff | 1406422432.787 | este é um registro de informação
2014-07-27 08:53:52 | NOTICE | 23625 | 599159975a9ff | 1406422432.787 | este é um registro de nota
2014-07-27 08:53:52 | WARNING | 23625 | 599159975a9ff | 1406422432.787 | seu github.com estava indisponível, favor reiniciar o quanto antes!
2014-07-27 08:53:52 | ERROR | 23625 | 599159975a9ff | 1406422432.787 | um registro de erro
2014-07-27 08:53:52 | CRITICAL | 23625 | 599159975a9ff | 1406422432.787 | alguma coisa crítica ocorreu
2014-07-27 08:53:52 | EMERGENCY | 23625 | 599159975a9ff | 1406422432.787 | Acontecendo agora, a casa ao lado está completamente em chamas! É brincadeira!
</pre></div>
  </div>
  <div class="example-contents"><p>O exemplo acima produzirá
algo semelhante a:</p></div>
  <div class="example-contents"><p>
   <em>seaslog.appender = 2</em> ou <em>seaslog.appender = 3</em>
  </p></div>
  <div class="example-contents screen">
<div class="cdata"><pre>
O estilo de registro fica formatado assim:
&lt;15&gt;1 2017-08-27T01:24:59+08:00 vagrant-ubuntu-trusty test/logger[27171]: 2016-06-25 00:59:43 | DEBUG | 21423 | 599157af4e937 | 1466787583.322 | esta é uma informação de depuração criada por maria
&lt;14&gt;1 2017-08-27T01:24:59+08:00 vagrant-ubuntu-trusty test/logger[27171]: 2016-06-25 00:59:43 | INFO | 21423 | 599157af4e937 | 1466787583.323 | este é um registro de informação
&lt;13&gt;1 2017-08-27T01:24:59+08:00 vagrant-ubuntu-trusty test/logger[27171]: 2016-06-25 00:59:43 | NOTICE | 21423 | 599157af4e937 | 1466787583.324 | este é um registro de nota
</pre></div>
  </div>
 </div>

 <div class="example" id="example-4">
  <p><strong>Exemplo #4 Contagem rápida de algum tipo de valor de contagem de registro</strong></p>
  <div class="example-contents"><p>
   <em>SeasLog</em> obtém o valor de contagem de `grep -wc`, usa o pipe do sistema e retorna para o PHP (array ou int).
  </p></div>
  <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$countResult1 </span><span style="color: #007700">= </span><span style="color: #0000BB">SeasLog</span><span style="color: #007700">::</span><span style="color: #0000BB">analyzerCount</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">$countResult2 </span><span style="color: #007700">= </span><span style="color: #0000BB">SeasLog</span><span style="color: #007700">::</span><span style="color: #0000BB">analyzerCount</span><span style="color: #007700">(</span><span style="color: #0000BB">SEASLOG_WARNING</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$countResult3 </span><span style="color: #007700">= </span><span style="color: #0000BB">SeasLog</span><span style="color: #007700">::</span><span style="color: #0000BB">analyzerCount</span><span style="color: #007700">(</span><span style="color: #0000BB">SEASLOG_ERROR</span><span style="color: #007700">,</span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">'Ymd'</span><span style="color: #007700">,</span><span style="color: #0000BB">time</span><span style="color: #007700">()));<br /><br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$countResult1</span><span style="color: #007700">,</span><span style="color: #0000BB">$countResult2</span><span style="color: #007700">,</span><span style="color: #0000BB">$countResult3</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
  </div>

  <div class="example-contents"><p>O exemplo acima produzirá
algo semelhante a:</p></div>
  <div class="example-contents screen">
<div class="cdata"><pre>
array(8) {
  [&quot;DEBUG&quot;]=&gt;
  int(3)
  [&quot;INFO&quot;]=&gt;
  int(3)
  [&quot;NOTICE&quot;]=&gt;
  int(3)
  [&quot;WARNING&quot;]=&gt;
  int(3)
  [&quot;ERROR&quot;]=&gt;
  int(6)
  [&quot;CRITICAL&quot;]=&gt;
  int(3)
  [&quot;ALERT&quot;]=&gt;
  int(3)
  [&quot;EMERGENCY&quot;]=&gt;
  int(3)
}
int(7)
int(1)
</pre></div>
  </div>
 </div>

 <div class="example" id="example-5">
  <p><strong>Exemplo #5 Adquirindo o tipo de lista de registros</strong></p>
  <div class="example-contents"><p>
   <em>SeasLog</em> obtém o valor de contagem de `grep -w`, usa o pipe do sistema e retorna o array para o PHP.
  </p></div>
  <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$detailErrorArray </span><span style="color: #007700">= </span><span style="color: #0000BB">SeasLog</span><span style="color: #007700">::</span><span style="color: #0000BB">analyzerDetail</span><span style="color: #007700">(</span><span style="color: #0000BB">SEASLOG_ERROR</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$detailErrorArray</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">SeasLog</span><span style="color: #007700">::</span><span style="color: #0000BB">analyzerDetail</span><span style="color: #007700">(</span><span style="color: #0000BB">SEASLOG_ERROR</span><span style="color: #007700">,</span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">'Ymd'</span><span style="color: #007700">,</span><span style="color: #0000BB">time</span><span style="color: #007700">())));<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
  </div>

  <div class="example-contents"><p>O exemplo acima produzirá
algo semelhante a:</p></div>
  <div class="example-contents screen">
<div class="cdata"><pre>
array(6) {
  [0] =&gt;
  string(83) &quot;2014-02-24 00:14:02 | ERROR | 8568 | 599157af4e937 | 1393172042.717 | erro de teste 3 &quot;
  [1] =&gt;
  string(83) &quot;2014-02-24 00:14:04 | ERROR | 8594 | 5991576584446 | 1393172044.104 | erro de teste 3 &quot;
  [2] =&gt;
  string(83) &quot;2014-02-24 00:14:04 | ERROR | 8620 | 1502697015147 | 1393172044.862 | erro de teste 3 &quot;
  [3] =&gt;
  string(83) &quot;2014-02-24 00:14:05 | ERROR | 8646 | 599159975a9ff | 1393172045.989 | erro de teste 3 &quot;
  [4] =&gt;
  string(83) &quot;2014-02-24 00:14:07 | ERROR | 8672 | 599159986ec28 | 1393172047.882 | erro de teste 3 &quot;
  [5] =&gt;
  string(83) &quot;2014-02-24 00:14:08 | ERROR | 8698 | 5991599981cec | 1393172048.736 | erro de teste 3 &quot;
}

array(2) {
  [0] =&gt;
  string(83) &quot;2014-02-24 00:14:02 | ERROR | 8568 | 599157af4e937 | 1393172042.717 | erro de teste 3 &quot;
  [1] =&gt;
  string(83) &quot;2014-02-24 00:14:04 | ERROR | 8594 | 5991576584446 | 1393172044.104 | erro de teste 3 &quot;
}
</pre></div>
  </div>
 </div>

</div>
<?php manual_footer($setup); ?>