PageRenderTime 73ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/administrator/components/com_virtuemart/classes/Log/error_log.php

http://vanphongphamdm.googlecode.com/
PHP | 120 lines | 36 code | 13 blank | 71 comment | 6 complexity | 7b0596f3d73302becc8346d227f032a1 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.1, Apache-2.0
  1. <?php
  2. if( !defined( '_VALID_MOS' ) && !defined( '_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__).' is not allowed.' );
  3. /**
  4. *
  5. * @version $Id: error_log.php 1336 2008-03-31 17:06:23Z soeren_nb $
  6. * @package VirtueMart
  7. * @subpackage Log
  8. * @copyright Copyright (C) 2004-2008 soeren - All rights reserved.
  9. * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
  10. * VirtueMart is free software. This version may have been modified pursuant
  11. * to the GNU General Public License, and as distributed it includes or
  12. * is derivative of works licensed under the GNU General Public License or
  13. * other free or open source software licenses.
  14. * See /administrator/components/com_virtuemart/COPYRIGHT.php for copyright notices and details.
  15. *
  16. * http://virtuemart.net
  17. */
  18. /**
  19. * $Header$
  20. *
  21. * @version $ Revision: 1.7 $
  22. * @package Log
  23. */
  24. /**
  25. * The vmLog_error_log class is a concrete implementation of the Log abstract
  26. * class that logs messages using PHP's error_log() function.
  27. *
  28. * @author Jon Parise <jon@php.net>
  29. * @since Log 1.7.0
  30. * @package Log
  31. *
  32. * @example error_log.php Using the error_log handler.
  33. */
  34. class vmLog_error_log extends vmLog
  35. {
  36. /**
  37. * The error_log() log type.
  38. * @var integer
  39. * @access private
  40. */
  41. var $_type = PEAR_LOG_TYPE_SYSTEM;
  42. /**
  43. * The type-specific destination value.
  44. * @var string
  45. * @access private
  46. */
  47. var $_destination = '';
  48. /**
  49. * Additional headers to pass to the mail() function when the
  50. * PEAR_LOG_TYPE_MAIL type is used.
  51. * @var string
  52. * @access private
  53. */
  54. var $_extra_headers = '';
  55. /**
  56. * Constructs a new vmLog_error_log object.
  57. *
  58. * @param string $name Ignored.
  59. * @param string $ident The identity string.
  60. * @param array $conf The configuration array.
  61. * @param int $level Log messages up to and including this level.
  62. * @access public
  63. */
  64. function vmLog_error_log($name, $ident = '', $conf = array(),
  65. $level = PEAR_LOG_DEBUG)
  66. {
  67. $this->_id = md5(microtime());
  68. $this->_type = $name;
  69. $this->_ident = $ident;
  70. $this->_mask = vmLog::UPTO($level);
  71. if (!empty($conf['destination'])) {
  72. $this->_destination = $conf['destination'];
  73. }
  74. if (!empty($conf['extra_headers'])) {
  75. $this->_extra_headers = $conf['extra_headers'];
  76. }
  77. }
  78. /**
  79. * Logs $message using PHP's error_log() function. The message is also
  80. * passed along to any Log_observer instances that are observing this Log.
  81. *
  82. * @param mixed $message String or object containing the message to log.
  83. * @param string $priority The priority of the message. Valid
  84. * values are: PEAR_LOG_EMERG, PEAR_LOG_ALERT,
  85. * PEAR_LOG_CRIT, PEAR_LOG_ERR, PEAR_LOG_WARNING,
  86. * PEAR_LOG_NOTICE, PEAR_LOG_INFO, and PEAR_LOG_DEBUG.
  87. * @return boolean True on success or false on failure.
  88. * @access public
  89. */
  90. function log($message, $priority = null)
  91. {
  92. /* If a priority hasn't been specified, use the default value. */
  93. if ($priority === null) {
  94. $priority = $this->_priority;
  95. }
  96. /* Abort early if the priority is above the maximum logging level. */
  97. if (!$this->_isMasked($priority)) {
  98. return false;
  99. }
  100. /* Extract the string representation of the message. */
  101. $message = $this->_extractMessage($message);
  102. $success = error_log($this->_ident . ': ' . $message, $this->_type,
  103. $this->_destination, $this->_extra_headers);
  104. $this->_announce(array('priority' => $priority, 'message' => $message));
  105. return $success;
  106. }
  107. }