Added: incubator/log4php/site/usage.html URL: http://svn.apache.org/viewvc/incubator/log4php/site/usage.html?view=auto&rev=558223 ============================================================================== --- incubator/log4php/site/usage.html (added) +++ incubator/log4php/site/usage.html Fri Jul 20 19:10:17 2007 @@ -0,0 +1,328 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> + + + + + + + + + + +<html> + <head> + <title>log4php - + Log4php Usage Example</title> + <style type="text/css" media="all"> + @import url("./css/maven-base.css"); + @import url("./css/maven-theme.css"); + @import url("./css/site.css"); + </style> + <link rel="stylesheet" href="./css/print.css" type="text/css" media="print" /> + <meta name="author" content=" + Marco Vassura" /> + <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> + </head> + <body class="composite"> + <div id="banner"> + <a href="http://logging.apache.org/" id="bannerLeft"> + + <img src="images/ls-logo.jpg" alt="" /> + + </a> + <div class="clear"> + <hr/> + </div> + </div> + <div id="breadcrumbs"> + + + + + + + + <div class="xleft"> + Last Published: 07/20/2007 + | + <a href="http://www.apache.org/">Apache</a> + > + + <a href="http://incubator.apache.org/">Incubator</a> + > + + log4php + </div> + <div class="xright"> + + + + + + + </div> + <div class="clear"> + <hr/> + </div> + </div> + <div id="leftColumn"> + <div id="navcolumn"> + + + + + + + + <h5>Get log4php</h5> + <ul> + + <li class="none"> + <a href="download.html">Download</a> + </li> + + <li class="none"> + <a href="changes-report.html">Changes</a> + </li> + + <li class="none"> + <a href="license.html">License</a> + </li> + </ul> + <h5>About log4php</h5> + <ul> + + <li class="none"> + <a href="index.html">What is it?</a> + </li> + + <li class="none"> + <a href="qsg.html">Quick start</a> + </li> + + <li class="none"> + <strong>Usage</strong> + </li> + + <li class="none"> + <a href="roadmap.html">Roadmap</a> + </li> + + <li class="none"> + <a href="apidocs/index.html">PHPDoc</a> + </li> + </ul> + <h5>Community</h5> + <ul> + + <li class="none"> + <a href="mail-lists.html">Mailing Lists</a> + </li> + + <li class="none"> + <a href="issue-tracking.html">Issue Tracking</a> + </li> + </ul> + <h5>Development</h5> + <ul> + + <li class="none"> + <a href="source-repository.html">Repository</a> + </li> + </ul> + <h5>Apache</h5> + <ul> + + <li class="none"> + <a href="http://www.apache.org">Home</a> + </li> + + <li class="none"> + <a href="http://www.apache.org/foundation/sponsorship.html">Sponsorship</a> + </li> + + <li class="none"> + <a href="http://www.apache.org/foundation/thanks.html">Thanks</a> + </li> + + <li class="none"> + <a href="http://www.apachecon.com">Conferences</a> + </li> + </ul> + <a href="http://maven.apache.org/" title="Built by Maven" id="poweredBy"> + <img alt="Built by Maven" src="./images/logos/maven-feather.png"></img> + </a> + + + + + + + + </div> + </div> + <div id="bodyColumn"> + <div id="contentBox"> + + + <meta name="keywords" content="php, java, logging, tracing, component, framework, API, log4php"></meta> + + <a name="Log4php Usage Example"></a><div class="section"><h2>Log4php Usage Example</h2> + <code><font color="#000000"> + <font color="#0000BB">&lt;?php + <br /> + <br /></font><font color="#FF8000">/** + <br /> * This is a log4php usage example file + <br /> * + <br /> * @version $Revision: 312325 $ + <br /> * @author Marco V. &lt;[EMAIL PROTECTED]&gt; + <br /> */ + <br /> + <br />/** + <br /> * Set LOG4PHP_DIR to Your log4php root dir or it will + <br /> * be set automatically at the first require_once(). + <br /> * Here 'log4php' is an 'include_path' subdir. + <br /> */ + <br /></font><font color="#0000BB">define</font><font color="#007700">(</font><font color="#DD0000">'LOG4PHP_DIR'</font><font color="#007700">, </font><font color="#DD0000">'log4php'</font><font color="#007700">); + <br /> + <br /></font><font color="#FF8000">/* + <br />&nbsp;&nbsp;&nbsp;&nbsp;1.&nbsp;&nbsp;If you want to use a custom Configurator, + <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set the LOG4PHP_CONFIGURATOR_CLASS constants to Your Configurator class file. + <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;The class name must have the same base name of the classfile. + <br /> + <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Ex: define('LOG4PHP_CONFIGURATOR_CLASS', '/my/path/LoggerMyConfigurator'); + <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; + <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Log4php will try to include '/my/path/LoggerMyConfigurator.php' + <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;and instantiate a 'LoggerMyConfigurator' class. + <br /> + <br />&nbsp;&nbsp;&nbsp;&nbsp;2.&nbsp;&nbsp;If you want to use a configuration file that's not the default, + <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set the LOG4PHP_CONFIGURATION constants to Your configuration filename. + <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; + <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Ex: define('LOG4PHP_CONFIGURATION', '/my/path/my_config.conf'); + <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; + <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Note that if config extension is NOT .xml and LOG4PHP_CONFIGURATOR_CLASS + <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;is not defined, the LoggerPropertyConfigurator will be used.&nbsp;&nbsp; + <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; + <br />&nbsp;&nbsp;&nbsp;&nbsp;3.&nbsp;&nbsp;If you want to bypass the initial configuration procedure, set the + <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'LOG4PHP_DEFAULT_INIT_OVERRIDE' to true. + <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; + <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Ex: define('LOG4PHP_DEFAULT_INIT_OVERRIDE', true); + <br />*/ + <br /> + <br /> + <br /></font><font color="#007700">require_once(</font><font color="#0000BB">LOG4PHP_DIR </font><font color="#007700">. </font><font color="#DD0000">'/LoggerManager.php'</font><font color="#007700">); + <br /></font><font color="#FF8000">/* + <br />&nbsp;&nbsp;&nbsp;&nbsp;Or You can use: + <br />&nbsp;&nbsp;&nbsp; + <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;require_once('/my/log4php/path/LoggerManager.php'); + <br />&nbsp;&nbsp;&nbsp;&nbsp; + <br />&nbsp;&nbsp;&nbsp;&nbsp;and LOG4PHP_DIR will be automatically set to '/my/log4php/path'. + <br />*/ + <br /> + <br /> + <br /></font><font color="#007700">class </font><font color="#0000BB">Test </font><font color="#007700">{ + <br /> + <br />&nbsp;&nbsp;&nbsp;&nbsp;var </font><font color="#0000BB">$logger</font><font color="#007700">; + <br /> + <br />&nbsp;&nbsp;&nbsp;&nbsp;function </font><font color="#0000BB">Test</font><font color="#007700">() + <br />&nbsp;&nbsp;&nbsp;&nbsp;{ + <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000BB">$this</font><font color="#007700">-&gt;</font><font color="#0000BB">logger </font><font color="#007700">=&amp; </font><font color="#0000BB">LoggerManager</font><font color="#007700">::</font><font color="#0000BB">getLogger</font><font color="#007700">(</font><font color="#DD0000">'Test'</font><font color="#007700">); + <br />&nbsp;&nbsp;&nbsp;&nbsp;} + <br />&nbsp;&nbsp;&nbsp;&nbsp; + <br />&nbsp;&nbsp;&nbsp;&nbsp;function </font><font color="#0000BB">testLog</font><font color="#007700">() + <br />&nbsp;&nbsp;&nbsp;&nbsp;{ + <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000BB">$this</font><font color="#007700">-&gt;</font><font color="#0000BB">logger</font><font color="#007700">-&gt;</font><font color="#0000BB">debug</font><font color="#007700">(</font><font color="#DD0000">'this is a DEBUG log generated by Test::testLog() class'</font><font color="#007700">); + <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000BB">$this</font><font color="#007700">-&gt;</font><font color="#0000BB">logger</font><font color="#007700">-&gt;</font><font color="#0000BB">info</font><font color="#007700">(</font><font color="#DD0000">'this is an INFO log generated by Test::testLog() class'</font><font color="#007700">); + <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000BB">$this</font><font color="#007700">-&gt;</font><font color="#0000BB">logger</font><font color="#007700">-&gt;</font><font color="#0000BB">warn</font><font color="#007700">(</font><font color="#DD0000">'this is a WARN log generated by Test::testLog() class'</font><font color="#007700">); + <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000BB">$this</font><font color="#007700">-&gt;</font><font color="#0000BB">logger</font><font color="#007700">-&gt;</font><font color="#0000BB">error</font><font color="#007700">(</font><font color="#DD0000">'this is an ERROR log generated by Test::testLog() class'</font><font color="#007700">); + <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000BB">$this</font><font color="#007700">-&gt;</font><font color="#0000BB">logger</font><font color="#007700">-&gt;</font><font color="#0000BB">fatal</font><font color="#007700">(</font><font color="#DD0000">'this is a FATAL log generated by Test::testLog() class'</font><font color="#007700">);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; + <br />&nbsp;&nbsp;&nbsp;&nbsp;} + <br /> + <br />} + <br /> + <br />class </font><font color="#0000BB">TestTest </font><font color="#007700">extends </font><font color="#0000BB">test </font><font color="#007700">{ + <br /> + <br />&nbsp;&nbsp;&nbsp;&nbsp;var </font><font color="#0000BB">$logger</font><font color="#007700">; + <br />&nbsp;&nbsp;&nbsp;&nbsp; + <br />&nbsp;&nbsp;&nbsp;&nbsp;function </font><font color="#0000BB">TestTest</font><font color="#007700">() + <br />&nbsp;&nbsp;&nbsp;&nbsp;{ + <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000BB">$this</font><font color="#007700">-&gt;</font><font color="#0000BB">Test</font><font color="#007700">();&nbsp;&nbsp;&nbsp;&nbsp; + <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000BB">$this</font><font color="#007700">-&gt;</font><font color="#0000BB">logger </font><font color="#007700">=&amp; </font><font color="#0000BB">LoggerManager</font><font color="#007700">::</font><font color="#0000BB">getLogger</font><font color="#007700">(</font><font color="#DD0000">'Test.Test'</font><font color="#007700">); + <br />&nbsp;&nbsp;&nbsp;&nbsp;} + <br />&nbsp;&nbsp;&nbsp;&nbsp; + <br />&nbsp;&nbsp;&nbsp;&nbsp;function </font><font color="#0000BB">testLog</font><font color="#007700">() + <br />&nbsp;&nbsp;&nbsp;&nbsp;{ + <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000BB">LoggerNDC</font><font color="#007700">::</font><font color="#0000BB">push</font><font color="#007700">(</font><font color="#DD0000">'NDC generated by TestTest::testLog()'</font><font color="#007700">); + <br />&nbsp;&nbsp;&nbsp;&nbsp; + <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000BB">$this</font><font color="#007700">-&gt;</font><font color="#0000BB">logger</font><font color="#007700">-&gt;</font><font color="#0000BB">debug</font><font color="#007700">(</font><font color="#DD0000">'this is a DEBUG log generated by TestTest::testLog() class'</font><font color="#007700">); + <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000BB">$this</font><font color="#007700">-&gt;</font><font color="#0000BB">logger</font><font color="#007700">-&gt;</font><font color="#0000BB">info</font><font color="#007700">(</font><font color="#DD0000">'this is an INFO log generated by TestTest::testLog() class'</font><font color="#007700">); + <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000BB">$this</font><font color="#007700">-&gt;</font><font color="#0000BB">logger</font><font color="#007700">-&gt;</font><font color="#0000BB">warn</font><font color="#007700">(</font><font color="#DD0000">'this is a WARN log generated by TestTest::testLog() class'</font><font color="#007700">); + <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000BB">$this</font><font color="#007700">-&gt;</font><font color="#0000BB">logger</font><font color="#007700">-&gt;</font><font color="#0000BB">error</font><font color="#007700">(</font><font color="#DD0000">'this is an ERROR log generated by TestTest::testLog() class'</font><font color="#007700">); + <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000BB">$this</font><font color="#007700">-&gt;</font><font color="#0000BB">logger</font><font color="#007700">-&gt;</font><font color="#0000BB">fatal</font><font color="#007700">(</font><font color="#DD0000">'this is a FATAL log generated by TestTest::testLog() class'</font><font color="#007700">); + <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; + <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000BB">LoggerNDC</font><font color="#007700">::</font><font color="#0000BB">pop</font><font color="#007700">();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; + <br />&nbsp;&nbsp;&nbsp;&nbsp;} + <br /> + <br />} + <br /> + <br />function </font><font color="#0000BB">Bar</font><font color="#007700">() + <br />{ + <br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000BB">$logger </font><font color="#007700">=&amp; </font><font color="#0000BB">LoggerManager</font><font color="#007700">::</font><font color="#0000BB">getLogger</font><font color="#007700">(</font><font color="#DD0000">'bar'</font><font color="#007700">); + <br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#FF8000">/* + <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;note that the message here is an array + <br />&nbsp;&nbsp;&nbsp;&nbsp;*/ + <br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000BB">$logger</font><font color="#007700">-&gt;</font><font color="#0000BB">debug</font><font color="#007700">(array(</font><font color="#DD0000">'one'</font><font color="#007700">, </font><font color="#DD0000">'two'</font><font color="#007700">, </font><font color="#DD0000">'tree'</font><font color="#007700">)); + <br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000BB">$logger</font><font color="#007700">-&gt;</font><font color="#0000BB">info</font><font color="#007700">(</font><font color="#DD0000">'this is an INFO log generated by Bar() function'</font><font color="#007700">); + <br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000BB">$logger</font><font color="#007700">-&gt;</font><font color="#0000BB">warn</font><font color="#007700">(</font><font color="#DD0000">'this is a WARN log generated by Bar() function'</font><font color="#007700">); + <br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000BB">$logger</font><font color="#007700">-&gt;</font><font color="#0000BB">error</font><font color="#007700">(</font><font color="#DD0000">'this is an ERROR log generated by Bar() function'</font><font color="#007700">); + <br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000BB">$logger</font><font color="#007700">-&gt;</font><font color="#0000BB">fatal</font><font color="#007700">(</font><font color="#DD0000">'this is a FATAL log generated by Bar() function'</font><font color="#007700">); + <br />&nbsp;&nbsp;&nbsp;&nbsp; + <br />} + <br /> + <br /></font><font color="#0000BB">$logger </font><font color="#007700">=&amp; </font><font color="#0000BB">LoggerManager</font><font color="#007700">::</font><font color="#0000BB">getLogger</font><font color="#007700">(</font><font color="#DD0000">'main'</font><font color="#007700">); + <br /> + <br /></font><font color="#0000BB">$logger</font><font color="#007700">-&gt;</font><font color="#0000BB">debug</font><font color="#007700">(</font><font color="#DD0000">'this is a DEBUG log generated by main() function'</font><font color="#007700">); + <br /></font><font color="#0000BB">$logger</font><font color="#007700">-&gt;</font><font color="#0000BB">info</font><font color="#007700">(</font><font color="#DD0000">'this is an INFO log generated by main() function'</font><font color="#007700">); + <br /></font><font color="#0000BB">$logger</font><font color="#007700">-&gt;</font><font color="#0000BB">warn</font><font color="#007700">(</font><font color="#DD0000">'this is a WARN log generated by main() function'</font><font color="#007700">); + <br /></font><font color="#0000BB">$logger</font><font color="#007700">-&gt;</font><font color="#0000BB">error</font><font color="#007700">(</font><font color="#DD0000">'this is an ERROR log generated by main() function'</font><font color="#007700">); + <br /></font><font color="#0000BB">$logger</font><font color="#007700">-&gt;</font><font color="#0000BB">fatal</font><font color="#007700">(</font><font color="#DD0000">'this is a FATAL log generated by main() function'</font><font color="#007700">);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; + <br /> + <br /> + <br /></font><font color="#0000BB">$test </font><font color="#007700">= new </font><font color="#0000BB">Test</font><font color="#007700">(); + <br /></font><font color="#0000BB">$test</font><font color="#007700">-&gt;</font><font color="#0000BB">testLog</font><font color="#007700">(); + <br /> + <br /></font><font color="#0000BB">$testTest </font><font color="#007700">= new </font><font color="#0000BB">TestTest</font><font color="#007700">(); + <br /></font><font color="#0000BB">$testTest</font><font color="#007700">-&gt;</font><font color="#0000BB">testLog</font><font color="#007700">(); + <br /> + <br /></font><font color="#0000BB">Bar</font><font color="#007700">(); + <br /> + <br /></font><font color="#0000BB">?&gt;</font> + </font> + </code> + </div> + + + </div> + </div> + <div class="clear"> + <hr/> + </div> + <div id="footer"> + <div class="xright">© + 2007 + + Apache Software Foundation + + + + + + + + </div> + <div class="clear"> + <hr/> + </div> + </div> + </body> +</html>
