Sophie

Sophie

distrib > Mageia > 7 > i586 > by-pkgid > 2b917e0437961edec048f1d15e2d7449 > files > 12412

php-manual-en-7.2.11-1.mga7.noarch.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Examples</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="seaslog.constants.html">Predefined Constants</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="ref.seaslog.html">Seaslog Functions</a></div>
 <div class="up"><a href="book.seaslog.html">Seaslog</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="seaslog.examples" class="chapter">
 <h1>Examples</h1>


 <div class="section">
  <div class="example" id="example-4688">
    <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 />&nbsp;&nbsp;$basePath1&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">SeasLog</span><span style="color: #007700">::</span><span style="color: #0000BB">getBasePath</span><span style="color: #007700">();<br /><br />&nbsp;&nbsp;</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 />&nbsp;&nbsp;</span><span style="color: #0000BB">$basePath2&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">SeasLog</span><span style="color: #007700">::</span><span style="color: #0000BB">getBasePath</span><span style="color: #007700">();<br /><br />&nbsp;&nbsp;</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 />&nbsp;&nbsp;</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>

<div class="section">
  <div class="example" id="example-4689">
    <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&nbsp;</span><span style="color: #007700">=&nbsp;</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&nbsp;</span><span style="color: #007700">=&nbsp;</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>
 
 <div class="section">
  <div class="example" id="example-4690">
    <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&nbsp;is&nbsp;a&nbsp;error&nbsp;test&nbsp;by&nbsp;::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&nbsp;is&nbsp;a&nbsp;{userName}&nbsp;debug'</span><span style="color: #007700">,array(</span><span style="color: #DD0000">'{userName}'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</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&nbsp;is&nbsp;a&nbsp;info&nbsp;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&nbsp;is&nbsp;a&nbsp;notice&nbsp;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&nbsp;{website}&nbsp;was&nbsp;down,please&nbsp;{action}&nbsp;it&nbsp;ASAP!'</span><span style="color: #007700">,array(</span><span style="color: #DD0000">'{website}'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'github.com'</span><span style="color: #007700">,</span><span style="color: #DD0000">'{action}'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</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&nbsp;error&nbsp;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&nbsp;thing&nbsp;was&nbsp;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&nbsp;this&nbsp;is&nbsp;a&nbsp;{messageName}'</span><span style="color: #007700">,array(</span><span style="color: #DD0000">'{messageName}'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</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&nbsp;now,&nbsp;the&nbsp;house&nbsp;next&nbsp;door&nbsp;was&nbsp;completely&nbsp;burnt&nbsp;out!&nbsp;{note}'</span><span style="color: #007700">,array(</span><span style="color: #DD0000">'{note}'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'it`s&nbsp;a&nbsp;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 class="emphasis">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 class="emphasis">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 class="emphasis">seaslog.appender = 2</em> or <em class="emphasis">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>

 <div class="section">
  <div class="example" id="example-4691">
    <p><strong>Example #4 Fast count some type of log count value</strong></p>
    <div class="example-contents"><p>
    <em class="emphasis">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&nbsp;</span><span style="color: #007700">=&nbsp;</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&nbsp;</span><span style="color: #007700">=&nbsp;</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&nbsp;</span><span style="color: #007700">=&nbsp;</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>

 <div class="section">
  <div class="example" id="example-4692">
    <p><strong>Example #5 Acquisit some type of log list</strong></p>
    <div class="example-contents"><p>
    <em class="emphasis">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&nbsp;</span><span style="color: #007700">=&nbsp;</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>

</div>
<hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="seaslog.constants.html">Predefined Constants</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="ref.seaslog.html">Seaslog Functions</a></div>
 <div class="up"><a href="book.seaslog.html">Seaslog</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>