PageRenderTime 307ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/magento/app/code/core/Mage/Core/Model/Log/Adapter.php

https://bitbucket.org/jit_bec/shopifine
PHP | 146 lines | 60 code | 9 blank | 77 comment | 11 complexity | ffbafb1e16dcc03cd3cb44dda3eddc29 MD5 | raw file
Possible License(s): LGPL-3.0
  1. <?php
  2. /**
  3. * Magento
  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@magentocommerce.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 Magento to newer
  18. * versions in the future. If you wish to customize Magento for your
  19. * needs please refer to http://www.magentocommerce.com for more information.
  20. *
  21. * @category Mage
  22. * @package Mage_Core
  23. * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
  24. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  25. */
  26. /**
  27. * Log Adapter
  28. *
  29. * @category Mage
  30. * @package Mage_Core
  31. * @author Magento Core Team <core@magentocommerce.com>
  32. */
  33. class Mage_Core_Model_Log_Adapter
  34. {
  35. /**
  36. * Store log file name
  37. *
  38. * @var string
  39. */
  40. protected $_logFileName = '';
  41. /**
  42. * Data to log
  43. *
  44. * @var array
  45. */
  46. protected $_data = array();
  47. /**
  48. * Fields that should be replaced in debug data with '***'
  49. *
  50. * @var array
  51. */
  52. protected $_debugReplacePrivateDataKeys = array();
  53. /**
  54. * Set log file name
  55. *
  56. * @param string $fileName
  57. */
  58. public function __construct($fileName)
  59. {
  60. $this->_logFileName = $fileName;
  61. }
  62. /**
  63. * Perform forced log data to file
  64. *
  65. * @param mixed $data
  66. * @return Mage_Core_Model_Log_Adapter
  67. */
  68. public function log($data = null)
  69. {
  70. if ($data === null) {
  71. $data = $this->_data;
  72. }
  73. else {
  74. if (!is_array($data)) {
  75. $data = array($data);
  76. }
  77. }
  78. $data = $this->_filterDebugData($data);
  79. $data['__pid'] = getmypid();
  80. Mage::log($data, null, $this->_logFileName, true);
  81. return $this;
  82. }
  83. /**
  84. * Log data setter
  85. *
  86. * @param string|array $key
  87. * @param mixed $value
  88. * @return Mage_Core_Model_Log_Adapter
  89. * @todo replace whole data
  90. */
  91. public function setData($key, $value = null)
  92. {
  93. if(is_array($key)) {
  94. $this->_data = $key;
  95. }
  96. else {
  97. $this->_data[$key] = $value;
  98. }
  99. return $this;
  100. }
  101. /**
  102. * Setter for private data keys, that should be replaced in debug data with '***'
  103. *
  104. * @param array $keys
  105. * @return Mage_Core_Model_Log_Adapter
  106. */
  107. public function setFilterDataKeys($keys)
  108. {
  109. if (!is_array($keys)) {
  110. $keys = array($keys);
  111. }
  112. $this->_debugReplacePrivateDataKeys = $keys;
  113. return $this;
  114. }
  115. /**
  116. * Recursive filter data by private conventions
  117. *
  118. * @param mixed $debugData
  119. * @return mixed
  120. */
  121. protected function _filterDebugData($debugData)
  122. {
  123. if (is_array($debugData) && is_array($this->_debugReplacePrivateDataKeys)) {
  124. foreach ($debugData as $key => $value) {
  125. if (in_array($key, $this->_debugReplacePrivateDataKeys)) {
  126. $debugData[$key] = '****';
  127. }
  128. else {
  129. if (is_array($debugData[$key])) {
  130. $debugData[$key] = $this->_filterDebugData($debugData[$key]);
  131. }
  132. }
  133. }
  134. }
  135. return $debugData;
  136. }
  137. }