<?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 => 'en',
  ),
  'this' => 
  array (
    0 => 'seaslog.examples.php',
    1 => 'Examples',
    2 => 'Examples',
  ),
  'up' => 
  array (
    0 => 'book.seaslog.php',
    1 => 'Seaslog',
  ),
  'prev' => 
  array (
    0 => 'seaslog.constants.php',
    1 => 'Predefined Constants',
  ),
  'next' => 
  array (
    0 => 'ref.seaslog.php',
    1 => 'Seaslog Functions',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    '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">Examples</h1>


 <div class="example" id="example-1">
  <p><strong>Example #1 Get and set base path</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>The above example will output
something similar to:</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>Example #2 Get and set logger</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>The above example will output
something similar to:</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>Example #3 Fast write log</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">'this is a error test by ::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">'this is a {userName} debug'</span><span style="color: #007700">,array(</span><span style="color: #DD0000">'{userName}' </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">'neeke'</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">'this is a info log'</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">'this is a notice log'</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">'your {website} was down,please {action} it ASAP!'</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">'rboot'</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">'a error log'</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">'some thing was critical'</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">'yes this is a {messageName}'</span><span style="color: #007700">,array(</span><span style="color: #DD0000">'{messageName}' </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">'alertMSG'</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">'Just now, the house next door was completely burnt out! {note}'</span><span style="color: #007700">,array(</span><span style="color: #DD0000">'{note}' </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">'it`s a joke'</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
  </div>

  <div class="example-contents"><p>
   As the default, <em>seaslog.default_template = &quot;%T | %L | %P | %Q | %t | %M&quot;</em>.
   That&#039;s mean,as the default,log record style is： `{dateTime} | {level} | {pid} | {uniqid} | {timeStamp} | {logInfo}`.
  </p></div>
  <div class="example-contents"><p>The above example will output
something similar to:</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 | this is a error test by log
2014-07-27 08:53:52 | DEBUG | 23625 | 599159975a9ff | 1406422432.786 | this is a neeke debug
2014-07-27 08:53:52 | INFO | 23625 | 599159975a9ff | 1406422432.787 | this is a info log
2014-07-27 08:53:52 | NOTICE | 23625 | 599159975a9ff | 1406422432.787 | this is a notice log
2014-07-27 08:53:52 | WARNING | 23625 | 599159975a9ff | 1406422432.787 | your github.com was down,please rboot it ASAP!
2014-07-27 08:53:52 | ERROR | 23625 | 599159975a9ff | 1406422432.787 | a error log
2014-07-27 08:53:52 | CRITICAL | 23625 | 599159975a9ff | 1406422432.787 | some thing was critical
2014-07-27 08:53:52 | EMERGENCY | 23625 | 599159975a9ff | 1406422432.787 | Just now, the house next door was completely burnt out! it is a joke
</pre></div>
  </div>
  <div class="example-contents"><p>The above example will output
something similar to:</p></div>
  <div class="example-contents"><p>
   <em>seaslog.appender = 2</em> or <em>seaslog.appender = 3</em>
  </p></div>
  <div class="example-contents screen">
<div class="cdata"><pre>
The log style finally formatted such as:
&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 | this is a neeke debug
&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 | this is a info log
&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 | this is a notice log
</pre></div>
  </div>
 </div>

 <div class="example" id="example-4">
  <p><strong>Example #4 Fast count some type of log count value</strong></p>
  <div class="example-contents"><p>
   <em>SeasLog</em> get count value of `grep -wc` use system pipe and return to PHP (array or 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>The above example will output
something similar to:</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>Example #5 Acquisit some type of log list</strong></p>
  <div class="example-contents"><p>
   <em>SeasLog</em> get count value of `grep -w` use system pipe and return array to 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>The above example will output
something similar to:</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 | test error 3 &quot;
  [1] =&gt;
  string(83) &quot;2014-02-24 00:14:04 | ERROR | 8594 | 5991576584446 | 1393172044.104 | test error 3 &quot;
  [2] =&gt;
  string(83) &quot;2014-02-24 00:14:04 | ERROR | 8620 | 1502697015147 | 1393172044.862 | test error 3 &quot;
  [3] =&gt;
  string(83) &quot;2014-02-24 00:14:05 | ERROR | 8646 | 599159975a9ff | 1393172045.989 | test error 3 &quot;
  [4] =&gt;
  string(83) &quot;2014-02-24 00:14:07 | ERROR | 8672 | 599159986ec28 | 1393172047.882 | test error 3 &quot;
  [5] =&gt;
  string(83) &quot;2014-02-24 00:14:08 | ERROR | 8698 | 5991599981cec | 1393172048.736 | test error 3 &quot;
}

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

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