LoggerLocationInfo.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. /**
  3. * log4php is a PHP port of the log4j java logging package.
  4. *
  5. * <p>This framework is based on log4j (see {@link http://jakarta.apache.org/log4j log4j} for details).</p>
  6. * <p>Design, strategies and part of the methods documentation are developed by log4j team
  7. * (Ceki Gülcü as log4j project founder and
  8. * {@link http://jakarta.apache.org/log4j/docs/contributors.html contributors}).</p>
  9. *
  10. * <p>PHP port, extensions and modifications by VxR. All rights reserved.<br>
  11. * For more information, please see {@link http://www.vxr.it/log4php/}.</p>
  12. *
  13. * <p>This software is published under the terms of the LGPL License
  14. * a copy of which has been included with this distribution in the LICENSE file.</p>
  15. *
  16. * @package log4php
  17. * @subpackage spi
  18. */
  19. /**
  20. * @ignore
  21. */
  22. if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..');
  23. /**
  24. * When location information is not available the constant
  25. * <i>NA</i> is returned. Current value of this string
  26. * constant is <b>?</b>.
  27. */
  28. define('LOG4PHP_LOGGER_LOCATION_INFO_NA', 'NA');
  29. /**
  30. * The internal representation of caller location information.
  31. *
  32. * @author VxR <vxr@vxr.it>
  33. * @version $Revision: 1.1 $
  34. * @package log4php
  35. * @subpackage spi
  36. * @since 0.3
  37. */
  38. class LoggerLocationInfo {
  39. /**
  40. * @var string Caller's line number.
  41. */
  42. var $lineNumber = null;
  43. /**
  44. * @var string Caller's file name.
  45. */
  46. var $fileName = null;
  47. /**
  48. * @var string Caller's fully qualified class name.
  49. */
  50. var $className = null;
  51. /**
  52. * @var string Caller's method name.
  53. */
  54. var $methodName = null;
  55. /**
  56. * @var string
  57. */
  58. var $fullInfo = null;
  59. /**
  60. * Instantiate location information based on a {@link PHP_MANUAL#debug_backtrace}.
  61. *
  62. * @param array $trace
  63. * @param mixed $caller
  64. */
  65. function LoggerLocationInfo($trace, $fqcn = null)
  66. {
  67. $this->lineNumber = isset($trace['line']) ? $trace['line'] : null;
  68. $this->fileName = isset($trace['file']) ? $trace['file'] : null;
  69. $this->className = isset($trace['class']) ? $trace['class'] : null;
  70. $this->methodName = isset($trace['function']) ? $trace['function'] : null;
  71. $this->fullInfo = $this->getClassName() . '.' . $this->getMethodName() .
  72. '(' . $this->getFileName() . ':' . $this->getLineNumber() . ')';
  73. }
  74. function getClassName()
  75. {
  76. return ($this->className === null) ? LOG4PHP_LOGGER_LOCATION_INFO_NA : $this->className;
  77. }
  78. /**
  79. * Return the file name of the caller.
  80. * <p>This information is not always available.
  81. */
  82. function getFileName()
  83. {
  84. return ($this->fileName === null) ? LOG4PHP_LOGGER_LOCATION_INFO_NA : $this->fileName;
  85. }
  86. /**
  87. * Returns the line number of the caller.
  88. * <p>This information is not always available.
  89. */
  90. function getLineNumber()
  91. {
  92. return ($this->lineNumber === null) ? LOG4PHP_LOGGER_LOCATION_INFO_NA : $this->lineNumber;
  93. }
  94. /**
  95. * Returns the method name of the caller.
  96. */
  97. function getMethodName()
  98. {
  99. return ($this->methodName === null) ? LOG4PHP_LOGGER_LOCATION_INFO_NA : $this->methodName;
  100. }
  101. }
  102. ?>