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

Revision 18220, 3.6 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 * @subpackage spi
21 */
22
23/**
24 * @ignore
25 */
26if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..');
27
28/**
29 * When location information is not available the constant
30 * <i>NA</i> is returned. Current value of this string
31 * constant is <b>?</b>. 
32 */
33define('LOG4PHP_LOGGER_LOCATION_INFO_NA',  'NA');
34
35/**
36 * The internal representation of caller location information.
37 *
38 * @author  Marco Vassura
39 * @version $Revision: 635069 $
40 * @package log4php
41 * @subpackage spi
42 * @since 0.3
43 */
44class LoggerLocationInfo {
45
46    /**
47    * @var string Caller's line number.
48    */
49    protected $lineNumber = null;
50   
51    /**
52    * @var string Caller's file name.
53    */
54    protected $fileName = null;
55   
56    /**
57    * @var string Caller's fully qualified class name.
58    */
59    protected $className = null;
60   
61    /**
62    * @var string Caller's method name.
63    */
64    protected $methodName = null;
65   
66    /**
67    * @var string
68    */
69    protected $fullInfo = null;
70
71    /**
72     * Instantiate location information based on a {@link PHP_MANUAL#debug_backtrace}.
73     *
74     * @param array $trace
75     * @param mixed $caller
76     */
77    public function __construct($trace, $fqcn = null)
78    {
79        $this->lineNumber   = isset($trace['line']) ? $trace['line'] : null;
80        $this->fileName     = isset($trace['file']) ? $trace['file'] : null;
81        $this->className    = isset($trace['class']) ? $trace['class'] : null;
82        $this->methodName   = isset($trace['function']) ? $trace['function'] : null;
83       
84        $this->fullInfo = $this->getClassName() . '.' . $this->getMethodName() .
85                          '(' . $this->getFileName() . ':' . $this->getLineNumber() . ')';
86    }
87
88    public function getClassName()
89    {
90        return ($this->className === null) ? LOG4PHP_LOGGER_LOCATION_INFO_NA : $this->className;
91    }
92
93    /**
94     *  Return the file name of the caller.
95     *  <p>This information is not always available.
96     */
97        public function getFileName()
98    {
99        return ($this->fileName === null) ? LOG4PHP_LOGGER_LOCATION_INFO_NA : $this->fileName;
100    }
101
102    /**
103     *  Returns the line number of the caller.
104     *  <p>This information is not always available.
105     */
106    public function getLineNumber()
107    {
108        return ($this->lineNumber === null) ? LOG4PHP_LOGGER_LOCATION_INFO_NA : $this->lineNumber;
109    }
110
111    /**
112     *  Returns the method name of the caller.
113     */
114    public function getMethodName()
115    {
116        return ($this->methodName === null) ? LOG4PHP_LOGGER_LOCATION_INFO_NA : $this->methodName;
117    }
118
119    /**
120     *  Returns the full information of the caller.
121     */
122    public function getFullInfo()
123    {
124        return ($this->fullInfo === null) ? LOG4PHP_LOGGER_LOCATION_INFO_NA : $this->fullInfo;
125    }
126}
Note: See TracBrowser for help on using the repository browser.