source: branches/comu-ver2/data/class/logger/GC_Logger.php @ 18220

Revision 18220, 3.5 KB checked in by yokkuns, 15 years ago (diff)

#149 ロガークラス作成

RevLine 
[18220]1<?php
2/*
3 * This file is part of EC-CUBE
4 *
5 * Copyright(c) 2000-2009 LOCKON CO.,LTD. All Rights Reserved.
6 *
7 * http://www.lockon.co.jp/
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22 */
23
24require_once (realpath(dirname(__FILE__)) . '/log/GC_Log_Log4php.php');
25
26/**
27 * loggerクラス
28 *
29 * ロギングを行うクラス
30 *
31 * @package Logger
32 * @author LOCKON CO.,LTD.
33 * @version $Id$
34 */
35
36class GC_Logger {
37    /** @var GC_Log_Interface ログインスタンス */
38    var $objLog;
39
40    /**
41     * コンストラクタ
42     *
43     * @param string logger名
44     * @return void
45     *
46     */
47    function GC_Logger($loggerName) {
48            $this->objLog = new GC_Log_Log4php($loggerName);
49    }
50
51    /**
52     * インスタンスの取得
53     *
54     *
55     * @param string logger名
56     * @return GC_Logger GC_Loggerインスタンス
57     *
58     */
59    function &gfGetInstance($loggerName='EC_CUBE') {
60        static $instances = array();
61
62        if(empty($loggerName)) {
63            $loggerName = 'EC_CUBE';
64        }
65
66        if(!array_key_exists($loggerName, $instances)) {
67            $instances[$loggerName] = new GC_Logger($loggerName);
68        }
69
70        return $instances[$loggerName];
71    }
72
73    /**
74     * ログ整形
75     *
76     * 文字列以外は、print_r形式に整形する
77     *
78     * @param mixed 出力したいログ
79     * @return mixed 整形されたログ
80     *
81     */
82    function lfCastLog($obj) {
83        if(!is_string($obj)) {
84            ob_start();
85            print_r($obj);
86            $obj = ob_get_contents();
87            ob_end_clean();
88        }
89
90        return $obj;
91    }
92
93    /**
94     * DEBUGログ
95     *
96     * @param string 出力したいログ
97     * @param mixed ダンプしたい変数
98     * @return void
99     *
100     */
101    function gfDebug($str, $dump='') {
102        $this->objLog->gfDebug($str . $this->lfCastLog($dump));
103    }
104
105    /**
106     * INFOログ
107     *
108     * @param string 出力したいログ
109     * @param mixed ダンプしたい変数
110     * @return void
111     *
112     */
113    function gfInfo($str, $dump='') {
114        $this->objLog->gfInfo($str . $this->lfCastLog($dump));
115    }
116
117    /**
118     * WARNログ
119     *
120     * @param string 出力したいログ
121     * @param mixed ダンプしたい変数
122     * @return void
123     *
124     */
125    function gfWarn($str, $dump='') {
126        $this->objLog->gfWarn($str . $this->lfCastLog($dump));
127    }
128
129    /**
130     * ERRORログ
131     *
132     * @param string 出力したいログ
133     * @param mixed ダンプしたい変数
134     * @return void
135     *
136     */
137    function gfError($str, $dump='') {
138        $this->objLog->gfError($str . $this->lfCastLog($dump));
139    }
140
141    /**
142     * FATALログ
143     *
144     * @param string 出力したいログ
145     * @param mixed ダンプしたい変数
146     * @return void
147     *
148     */
149    function gfFatal($str, $dump='') {
150        $this->objLog->gfFatal($str . $this->lfCastLog($dump));
151    }
152}
153?>
Note: See TracBrowser for help on using the repository browser.