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

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

#149 ロガークラス作成

Line 
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 */
21
22/**
23 * @ignore
24 */
25if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__));
26 
27/**
28 * Abstract class that defines output logs strategies.
29 *
30 * @author  Marco Vassura
31 * @version $Revision: 635069 $
32 * @package log4php
33 */
34abstract class LoggerAppender {
35
36    /**
37     * Factory
38     *
39     * @param string $name appender name
40     * @param string $class create an instance of this appender class
41     * @return LoggerAppender
42     */
43    public static function factory($name, $class)
44    {
45        $class = basename($class);
46        if (!empty($class)) {
47               
48            if (!class_exists($class))
49                include_once(LOG4PHP_DIR . "/appenders/{$class}.php");
50            if (class_exists($class))
51                return new $class($name);
52        }
53        return null;
54    }
55   
56    /**
57     * Singleton
58     *
59     * @param string $name appender name
60     * @param string $class create or get a reference instance of this class
61     * @return LoggerAppender
62     */
63    public static function singleton($name, $class = '')
64    {
65        static $instances;
66       
67        if (!empty($name)) {
68            if (!isset($instances[$name])) {
69                if (!empty($class)) {
70                    $appender = self::factory($name, $class);
71                    if ($appender !== null) {
72                        $instances[$name] = $appender;
73                        return $instances[$name];
74                    }
75                }
76                return null;
77            }
78            return $instances[$name];               
79        }       
80        return null;       
81    }
82   
83    /* --------------------------------------------------------------------------*/
84    /* --------------------------------------------------------------------------*/
85    /* --------------------------------------------------------------------------*/
86   
87    /**
88     * Add a filter to the end of the filter list.
89     *
90     * @param LoggerFilter $newFilter add a new LoggerFilter
91     * @abstract
92     */
93    abstract public function addFilter($newFilter);
94   
95    /**
96     * Clear the list of filters by removing all the filters in it.
97     * @abstract
98     */
99    abstract function clearFilters();
100
101    /**
102     * Return the first filter in the filter chain for this Appender.
103     * The return value may be <i>null</i> if no is filter is set.
104     * @return LoggerFilter
105     */
106    abstract function getFilter();
107   
108    /**
109     * Release any resources allocated.
110     * Subclasses of {@link LoggerAppender} should implement
111     * this method to perform proper closing procedures.
112     * @abstract
113     */
114    abstract public function close();
115
116    /**
117     * This method performs threshold checks and invokes filters before
118     * delegating actual logging to the subclasses specific <i>append()</i> method.
119     * @param LoggerLoggingEvent $event
120     * @abstract
121     */
122    abstract public function doAppend($event);
123
124    /**
125     * Get the name of this appender.
126     * @return string
127     */
128    abstract public function getName();
129
130    /**
131     * Do not use this method.
132     *
133     * @param object $errorHandler
134     */
135    abstract public function setErrorHandler($errorHandler);
136   
137    /**
138     * Do not use this method.
139     * @return object Returns the ErrorHandler for this appender.
140     */
141    abstract public function getErrorHandler();
142
143    /**
144     * Set the Layout for this appender.
145     *
146     * @param LoggerLayout $layout
147     */
148    abstract public function setLayout($layout);
149   
150    /**
151     * Returns this appender layout.
152     * @return LoggerLayout
153     */
154    abstract public function getLayout();
155
156    /**
157     * Set the name of this appender.
158     *
159     * The name is used by other components to identify this appender.
160     *
161     * @param string $name
162     */
163    abstract public function setName($name);
164
165    /**
166     * Configurators call this method to determine if the appender
167     * requires a layout.
168     *
169     * <p>If this method returns <i>true</i>, meaning that layout is required,
170     * then the configurator will configure a layout using the configuration
171     * information at its disposal.  If this method returns <i>false</i>,
172     * meaning that a layout is not required, then layout configuration will be
173     * skipped even if there is available layout configuration
174     * information at the disposal of the configurator.</p>
175     *
176     * <p>In the rather exceptional case, where the appender
177     * implementation admits a layout but can also work without it, then
178     * the appender should return <i>true</i>.</p>
179     *
180     * @return boolean
181     */
182    abstract public function requiresLayout();
183
184}
Note: See TracBrowser for help on using the repository browser.