source: branches/comu-ver2/data/module/log4php/php5/log4php/appenders/LoggerAppenderPhp.php @ 18220

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

#149 ロガークラス作成

RevLine 
[18220]1<?php
2/**
3 * Licensed to the Apache Software Foundation (ASF) under one or more
4 * contributor license agreements.  See the NOTICE file distributed with
5 * this work for additional information regarding copyright ownership.
6 * The ASF licenses this file to You under the Apache License, Version 2.0
7 * (the "License"); you may not use this file except in compliance with
8 * the License.  You may obtain a copy of the License at
9 *
10 *     http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 *
19 * @package log4php
20 * @subpackage appenders
21 */
22
23/**
24 * @ignore
25 */
26if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..');
27 
28require_once(LOG4PHP_DIR . '/LoggerAppenderSkeleton.php');
29require_once(LOG4PHP_DIR . '/LoggerLevel.php');
30require_once(LOG4PHP_DIR . '/LoggerLog.php');
31
32/**
33 * Log events using php {@link PHP_MANUAL#trigger_error} function and a {@link LoggerLayoutTTCC} default layout.
34 *
35 * <p>Levels are mapped as follows:</p>
36 * - <b>level &lt; WARN</b> mapped to E_USER_NOTICE
37 * - <b>WARN &lt;= level &lt; ERROR</b> mapped to E_USER_WARNING
38 * - <b>level &gt;= ERROR</b> mapped to E_USER_ERROR 
39 *
40 * @author  Marco Vassura
41 * @version $Revision: 635069 $
42 * @package log4php
43 * @subpackage appenders
44 */
45class LoggerAppenderPhp extends LoggerAppenderSkeleton {
46
47   
48    public function activateOptions() {
49        $this->layout = LoggerLayout::factory('LoggerLayoutTTCC');
50        $this->closed = false;
51    }
52
53    public function close() {
54        $this->closed = true;
55    }
56
57    public function append($event) {
58        if ($this->layout !== null) {
59            LoggerLog::debug("LoggerAppenderPhp::append()");
60            $level = $event->getLevel();
61            if ($level->isGreaterOrEqual(LoggerLevel::getLevelError())) {
62                trigger_error($this->layout->format($event), E_USER_ERROR);
63            } elseif ($level->isGreaterOrEqual(LoggerLevel::getLevelWarn())) {
64                trigger_error($this->layout->format($event), E_USER_WARNING);
65            } else {
66                trigger_error($this->layout->format($event), E_USER_NOTICE);
67            }
68        }
69    }
70}
Note: See TracBrowser for help on using the repository browser.