PageRenderTime 36ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/classes/log/AbstractLogger.php

https://bitbucket.org/enurkov/prestashop
PHP | 110 lines | 44 code | 10 blank | 56 comment | 2 complexity | 28e8c1a4d56b908c0a555888dcff4241 MD5 | raw file
  1. <?php
  2. /*
  3. * 2007-2012 PrestaShop
  4. *
  5. * NOTICE OF LICENSE
  6. *
  7. * This source file is subject to the Open Software License (OSL 3.0)
  8. * that is bundled with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://opensource.org/licenses/osl-3.0.php
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@prestashop.com so we can send you a copy immediately.
  14. *
  15. * DISCLAIMER
  16. *
  17. * Do not edit or add to this file if you wish to upgrade PrestaShop to newer
  18. * versions in the future. If you wish to customize PrestaShop for your
  19. * needs please refer to http://www.prestashop.com for more information.
  20. *
  21. * @author PrestaShop SA <contact@prestashop.com>
  22. * @copyright 2007-2012 PrestaShop SA
  23. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  24. * International Registered Trademark & Property of PrestaShop SA
  25. */
  26. abstract class AbstractLoggerCore
  27. {
  28. public $level;
  29. protected $level_value = array(
  30. 0 => 'DEBUG',
  31. 1 => 'INFO',
  32. 2 => 'WARNING',
  33. 3 => 'ERROR',
  34. );
  35. const DEBUG = 0;
  36. const INFO = 1;
  37. const WARNING = 2;
  38. const ERROR = 3;
  39. public function __construct($level = self::INFO)
  40. {
  41. if (array_key_exists((int)$level, $this->level_value))
  42. $this->level = $level;
  43. else
  44. $this->level = self::INFO;
  45. }
  46. /**
  47. * Log the message
  48. *
  49. * @param string message
  50. * @param level
  51. */
  52. abstract protected function logMessage($message, $level);
  53. /**
  54. * Check the level and log the message if needed
  55. *
  56. * @param string message
  57. * @param level
  58. */
  59. public function log($message, $level = self::DEBUG)
  60. {
  61. if ($level >= $this->level)
  62. $this->logMessage($message, $level);
  63. }
  64. /**
  65. * Log a debug message
  66. *
  67. * @param string message
  68. */
  69. public function logDebug($message)
  70. {
  71. $this->log($message, self::DEBUG);
  72. }
  73. /**
  74. * Log an info message
  75. *
  76. * @param string message
  77. */
  78. public function logInfo($message)
  79. {
  80. $this->log($message, self::INFO);
  81. }
  82. /**
  83. * Log a warning message
  84. *
  85. * @param string message
  86. */
  87. public function logWarning($message)
  88. {
  89. $this->log($message, self::WARNING);
  90. }
  91. /**
  92. * Log an error message
  93. *
  94. * @param string message
  95. */
  96. public function logError($message)
  97. {
  98. $this->log($message, self::ERROR);
  99. }
  100. }