<?php
/**
 * -----------------------------------------------------------------------------
 *
 * SyL - Web Application Framework for PHP
 *
 * PHP version 4 (>= 4.3.x) or 5
 *
 * Copyright (C) 2006 k.watanabe
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * -----------------------------------------------------------------------------
 * @package   SyL
 * @author    k.watanabe <k.watanabe@syl.jp>
 * @copyright 2006 k.watanabe
 * @license   http://www.opensource.org/licenses/lgpl-license.php
 * @version   CVS: $Id: SyL_Logger.php,v 1.8 2006/12/25 17:30:18 seasonstream Exp $
 * @link      http://www.syl.jp/
 * -----------------------------------------------------------------------------
 */

/**
 * ログ出力クラス
 * 
 * @package   SyL
 * @author    k.watanabe <k.watanabe@syl.jp>
 * @copyright 2006 k.watanabe
 * @license   http://www.opensource.org/licenses/lgpl-license.php
 * @version   CVS: $Id: SyL_Logger.php,v 1.8 2006/12/25 17:30:18 seasonstream Exp $
 * @link      http://www.syl.jp/
 */
class SyL_Logger
{
    /**
     * リクエストメソッド
     * 
     * @access public
     * @var string
     */
    var $request_method;
    /**
     * クライアントIPアドレス
     * 
     * @access public
     * @var string
     */
    var $remote_addr;
    /**
     * リクエストURL
     * 
     * @access public
     * @var string
     */
    var $request_uri;
    /**
     * 即時出力フラグ
     * 
     * @access public
     * @var bool
     */
    var $immediate = true;
    /**
     * 即時出力ではない場合に格納するバッファ
     * 
     * @access public
     * @var array
     */
    var $buffer = array();
    /**
     * 改行コード
     * 
     * @access public
     * @var string
     */
    var $eof = "\r\n";

    /**
     * コンストラクタ
     *
     * @access public
     * @param boolean ログ即時出力フラグ true: 即時出力、false: リクエスト終了後に出力
     */
    function SyL_Logger($immediate=true)
    {
        $this->request_method = isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : '';
        $this->remote_addr    = isset($_SERVER['REMOTE_ADDR'])    ? $_SERVER['REMOTE_ADDR']    : '';
        $this->request_uri    = isset($_SERVER['REQUEST_URI'])    ? $_SERVER['REQUEST_URI']    : '';
        $this->immediate = $immediate;
    }

    /**
     * ログオブジェクトの取得
     *
     * @access public
     * @param string ログカテゴリ名
     * @param boolean ログ即時出力フラグ true: 即時出力、false: リクエスト終了後に出力
     * @return object ログオブジェクト
     */
    function &getLogger($type, $immediate=true)
    {
        // ログカテゴリオブジェクト読み込み
        $logger_class = 'SyL_Logger' . ucfirst($type);
        include_once SYL_INCLUDE_DIR . '/framework/Logger/' . $logger_class . '.php';
        $logger_object =& new $logger_class($immediate);
        return $logger_object;
    }

    /**
     * オープン
     *
     * @access public
     */
    function open()
    {
    }

    /**
     * ログの出力
     *
     * @access public
     * @param string ログレベル名
     * @param string メッセージ
     */
    function log($level, $message)
    {
    }

    /**
     * ログの全出力
     *
     * @access public
     */
    function logAll()
    {
        if (!$this->immediate) {
            while (true) {
                $buffer = array_shift($this->buffer);
                if (($buffer === false) || ($buffer === null)) {
                    break;
                }
                $this->log( '', $buffer );
            }
        }
    }

    /**
     * 閉じる
     *
     * @access public
     */
    function close()
    {
        $this->logAll();
    }

}

?>
