PageRenderTime 49ms CodeModel.GetById 27ms RepoModel.GetById 1ms app.codeStats 0ms

/www/shop/engine/Library/Enlight/Components/Log.php

https://bitbucket.org/weberlars/sot-shopware
PHP | 108 lines | 45 code | 10 blank | 53 comment | 13 complexity | 3527df8c250d74ff631ae5e7e80395fe MD5 | raw file
Possible License(s): AGPL-3.0, MIT, BSD-3-Clause, LGPL-2.1, LGPL-3.0
  1. <?php
  2. /**
  3. * Enlight
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://enlight.de/license/new-bsd
  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@shopware.de so we can send you a copy immediately.
  14. *
  15. * @category Enlight
  16. * @package Enlight_Log
  17. * @copyright Copyright (c) 2011, shopware AG (http://www.shopware.de)
  18. * @license http://enlight.de/license/new-bsd New BSD License
  19. * @version $Id$
  20. * @author Heiner Lohaus
  21. * @author $Author$
  22. */
  23. /**
  24. * Basic Enlight log component.
  25. *
  26. * The Enlight_Components_Log is a component to log data and to output these via appropriate log writer.
  27. *
  28. * @category Enlight
  29. * @package Enlight_Log
  30. * @copyright Copyright (c) 2011, shopware AG (http://www.shopware.de)
  31. * @license http://enlight.de/license/new-bsd New BSD License
  32. *
  33. * @method mixed table()
  34. * @method mixed exception()
  35. * @method mixed dump()
  36. * @method mixed trace()
  37. * @method mixed err()
  38. */
  39. class Enlight_Components_Log extends Zend_Log
  40. {
  41. const TABLE = 8;
  42. const EXCEPTION = 9;
  43. const DUMP = 10;
  44. const TRACE = 11;
  45. /**
  46. * Factory to construct the logger and one or more writers
  47. * based on the configuration array
  48. *
  49. * @throws Zend_Log_Exception
  50. * @param Enlight_Config|array $config
  51. * @return Enlight_Components_Log
  52. */
  53. static public function factory($config = array())
  54. {
  55. if ($config instanceof Zend_Config) {
  56. $config = $config->toArray();
  57. }
  58. if (!is_array($config) || empty($config)) {
  59. throw new Enlight_Exception('Configuration must be an array or instance of Enlight_Config');
  60. }
  61. $log = new self;
  62. if (array_key_exists('timestampFormat', $config)) {
  63. if (null != $config['timestampFormat'] && '' != $config['timestampFormat']) {
  64. $log->setTimestampFormat($config['timestampFormat']);
  65. }
  66. unset($config['timestampFormat']);
  67. }
  68. if (!is_array(current($config))) {
  69. $log->addWriter(current($config));
  70. } else {
  71. foreach ($config as $writer) {
  72. $log->addWriter($writer);
  73. }
  74. }
  75. return $log;
  76. }
  77. /**
  78. * Add a writer. A writer is responsible for taking a log
  79. * message and writing it out to storage.
  80. *
  81. * @param mixed $writer Zend_Log_Writer_Abstract or Config array
  82. * @return Zend_Log
  83. */
  84. public function addWriter($writer)
  85. {
  86. if (is_array($writer) || $writer instanceof Zend_Config) {
  87. $writer = $this->_constructWriterFromConfig($writer);
  88. }
  89. if ($writer instanceof Zend_Log_Writer_Firebug) {
  90. /** @var $writer Zend_Log_Writer_Firebug */
  91. $writer->setPriorityStyle(self::TABLE, 'TABLE');
  92. $writer->setPriorityStyle(self::EXCEPTION, 'EXCEPTION');
  93. $writer->setPriorityStyle(self::DUMP, 'DUMP');
  94. $writer->setPriorityStyle(self::TRACE, 'TRACE');
  95. }
  96. return parent::addWriter($writer);
  97. }
  98. }