zoukankan      html  css  js  c++  java
  • CI中使用log4php调试程序

    下载log4php。我下载的版本是:apache-log4php-2.3.0-src.zip。借压缩,将压缩文件中的src/main/php/文件夹拷贝到CI的application/thrid_party/目录中,并将此文件夹(php),改名为log4php。

    在log4php文件夹中建立log4php的配置文件,文件名为:log4php.properties。此配置文件内容如下:

    log4php.rootLogger=DEBUG, A1
    
    #输出到页面
    log4php.appender.A1 = LoggerAppenderEcho
    log4php.appender.A1.layout = LoggerLayoutHtml
    
    #输出到文件
    log4php.appender.A2 = LoggerAppenderDailyFile
    log4php.appender.A2.layout = LoggerLayoutPattern
    log4php.appender.A2.layout.ConversionPattern = "%d{ISO8601} [%p] %c: %m (at %F line %L)%n"
    log4php.appender.A2.datePattern = Ymd
    log4php.appender.A2.file = logs/errorLog_%s.log
    
    log4php的信息会显示在页面上。

    打开根目录下的index.php文件,在文件中添加入下代码:

    // 载入Log4php
    define('LOG4PHP_DIR', APPPATH.'third_party/log4php/');
    require_once LOG4PHP_DIR.'Logger.php';
    Logger::configure(LOG4PHP_DIR.'log4php.properties');
     
    /*
     * --------------------------------------------------------------------
     * LOAD THE BOOTSTRAP FILE
     * --------------------------------------------------------------------
     *
     * And away we go...
     *
     */
    require_once BASEPATH.'core/CodeIgniter.php';
    
    在需要调试的文件中,如/application/controllers/index/test.php文件中:

    <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
    
    class Test extends CI_Router {
        // 定义私有日志变量log
        private $log;
        
        /**
         * Constructor
         * Runs the route mapping function.
         */
        public function __construct() {
            parent::__construct();
            // 生成log
            $this->log = Logger::getLogger(__CLASS__);
            // 使用log
            $this->log->debug('Class Initialized');
        }
    	function index(){
    		$a = 'aaa';
    		$this->log->info('index_test:'.$a);
    		die('end');
    	}
    }



  • 相关阅读:
    Winform中在ZedGraph中最多可以添加多少条曲线(转)
    c#委托的含义和用法
    vs2010打开vs2017工程
    C# Socket编程资源
    C# 调用打印机 打印 Excel (转)
    NPOI 教程
    C# 调用C++ DLL 的类型转换(转载版)(转)
    进程间通信(网络阅读笔记)
    NPOI 第二篇 设置样式与合并单元格(转)
    分布式事务的 6 种解决方案,写得非常好!
  • 原文地址:https://www.cnblogs.com/moqiang02/p/4061098.html
Copyright © 2011-2022 走看看