{"id":25,"date":"2007-12-26T01:54:23","date_gmt":"2007-12-25T17:54:23","guid":{"rendered":"http:\/\/amjet.dyndns.biz\/blog\/IT\/?p=25"},"modified":"2013-03-01T19:50:47","modified_gmt":"2013-03-01T11:50:47","slug":"php-%e7%a8%8b%e5%bc%8f%e9%96%8b%e7%99%bc%e7%9a%84-log-framework","status":"publish","type":"post","link":"https:\/\/blog.amjet.biz\/IT\/?p=25","title":{"rendered":"PHP \u7a0b\u5f0f\u958b\u767c\u7684 Log framework"},"content":{"rendered":"<p>log4j \u5e7e\u4e4e\u5df2\u7d93\u662f java \u5c08\u6848\u958b\u767c\u7684\u6a19\u6e96\u914d\u5099\u4e86\uff0c\u5728 pear \u7db2\u7ad9\u641c\u5c0b\u4e86\u4e00\u4e0b\uff0c\u627e\u5230\u4e86\u4e00\u500b logging \u7684\u5957\u4ef6\uff0c\u5b89\u88dd\u5bb9\u6613\uff0c\u6574\u5408\u4e5f\u975e\u5e38\u65b9\u4fbf\u3002<\/p>\n<p>\u5b89\u88dd\u90e8\u4efd\uff1a<\/p>\n<p>Fedora 8 \u53ea\u8981 &#8216;yum install php-pear-Log&#8217; \u5c31\u6703\u81ea\u52d5\u5b89\u88dd\u597d\u6240\u9700\u7684\u5957\u4ef6\uff0cWindows \u6216\u5176\u4ed6\u5e73\u53f0\u5982\u679c\u5df2\u7d93\u5b89\u88dd\u597d PHP\u3001PEAR \u5957\u4ef6\uff0c\u61c9\u8a72\u53ea\u8981 &#8216;pear install Log&#8217; \u5c31\u6703\u81ea\u52d5\u4e0b\u8f09\u4e26\u5b89\u88dd\u597d\u5957\u4ef6\uff0cwindows \u7684 xampp \u662f\u9019\u6a23\u5b89\u88dd\u597d\u7684\u3002<\/p>\n<p>Coding\uff1a<\/p>\n<p>\u4ee5\u4e0b\u662f\u4e00\u5c0f\u6bb5\u7c21\u77ed\u7684\u7bc4\u4f8b<\/p>\n<p>&lt;?php<\/p>\n<p>require_once &#8216;Log.php&#8217;;<\/p>\n<p>$logger=&amp;Log::factory(&#8216;file&#8217;,&#8217;myap.log&#8217;,&#8217;demo.php&#8217;);<br \/>\n$logger-&gt;log(&#8216;application start&#8217;,PEAR_LOG_NOTICE);<br \/>\n$logger-&gt;log(&#8216;application finished&#8217;,PEAR_LOG_NOTICE);<\/p>\n<p>?&gt;<\/p>\n<p>\u5beb\u9032 myap.log \u6a94\u7684 log \u683c\u5f0f\u5982\u4e0b<\/p>\n<p>Dec 26 01:11:22 demo.php [notice] application start<br \/>\nDec 26 01:11:22 demo.php [notice] application finished<\/p>\n<p>\u652f\u63f4\u7684 log level \u5305\u62ec<\/p>\n<p>PEAR_LOG_EMERG<\/p>\n<p>PEAR_LOG_ALERT<\/p>\n<p>PEAR_LOG_CRIT<\/p>\n<p>PEAR_LOG_ERR<\/p>\n<p>PEAR_LOG_WARNING<\/p>\n<p>PEAR_LOG_NOTICE<\/p>\n<p>PEAR_LOG_INFO<\/p>\n<p>PEAR_LOG_DEBUG<\/p>\n<p><strong>[ratings]<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>log4j \u5e7e\u4e4e\u5df2\u7d93\u662f java \u5c08\u6848\u958b\u767c\u7684\u6a19\u6e96\u914d\u5099\u4e86\uff0c\u5728 pear \u7db2\u7ad9\u641c\u5c0b\u4e86\u4e00\u4e0b\uff0c\u627e\u5230\u4e86\u4e00\u500b logging \u7684\u5957\u4ef6\uff0c\u5b89\u88dd\u5bb9\u6613\uff0c\u6574\u5408\u4e5f\u975e\u5e38\u65b9\u4fbf\u3002 \u5b89\u88dd\u90e8\u4efd\uff1a Fedora 8 \u53ea\u8981 &#8216;yum install php-pear-Log&#8217; \u5c31\u6703\u81ea\u52d5\u5b89\u88dd\u597d\u6240\u9700\u7684\u5957\u4ef6\uff0cWindows \u6216\u5176\u4ed6\u5e73\u53f0\u5982\u679c\u5df2\u7d93\u5b89\u88dd\u597d PHP\u3001PEAR \u5957\u4ef6\uff0c\u61c9\u8a72\u53ea\u8981 &#8216;pear install Log&#8217; \u5c31\u6703\u81ea\u52d5\u4e0b\u8f09\u4e26\u5b89\u88dd\u597d\u5957\u4ef6\uff0cwindows \u7684 xampp \u662f\u9019\u6a23\u5b89\u88dd\u597d\u7684\u3002 Coding\uff1a \u4ee5\u4e0b\u662f\u4e00\u5c0f\u6bb5\u7c21\u77ed\u7684\u7bc4\u4f8b &lt;?php require_once &#8216;Log.php&#8217;; $logger=&amp;Log::factory(&#8216;file&#8217;,&#8217;myap.log&#8217;,&#8217;demo.php&#8217;); $logger-&gt;log(&#8216;application start&#8217;,PEAR_LOG_NOTICE); $logger-&gt;log(&#8216;application finished&#8217;,PEAR_LOG_NOTICE); ?&gt; \u5beb\u9032 myap.log \u6a94\u7684 log \u683c\u5f0f\u5982\u4e0b Dec 26 01:11:22 demo.php [notice] application start Dec 26 01:11:22 demo.php [notice] application [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[91,137],"class_list":["post-25","post","type-post","status-publish","format-standard","hentry","category-php","tag-log","tag-php"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/blog.amjet.biz\/IT\/index.php?rest_route=\/wp\/v2\/posts\/25","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.amjet.biz\/IT\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.amjet.biz\/IT\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.amjet.biz\/IT\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.amjet.biz\/IT\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=25"}],"version-history":[{"count":4,"href":"https:\/\/blog.amjet.biz\/IT\/index.php?rest_route=\/wp\/v2\/posts\/25\/revisions"}],"predecessor-version":[{"id":739,"href":"https:\/\/blog.amjet.biz\/IT\/index.php?rest_route=\/wp\/v2\/posts\/25\/revisions\/739"}],"wp:attachment":[{"href":"https:\/\/blog.amjet.biz\/IT\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=25"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.amjet.biz\/IT\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=25"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.amjet.biz\/IT\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=25"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}