PageRenderTime 41ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/heart/reborn/src/Reborn/Cores/Log.php

https://bitbucket.org/yelinaung/reborn
PHP | 165 lines | 53 code | 21 blank | 91 comment | 0 complexity | 0ffe7a77128e9ca293269e19e9e37814 MD5 | raw file
  1. <?php
  2. namespace Reborn\Cores;
  3. use Monolog\Logger;
  4. use Monolog\Handler\StreamHandler;
  5. /**
  6. * Log Class for Reborn CMS
  7. *
  8. * This class is really adapter only between Monolog and Reborn CMS.
  9. * Supported logging methods are -
  10. * -- debug
  11. * -- info
  12. * -- notice
  13. * -- warning
  14. * -- error
  15. * -- critical
  16. * -- alert
  17. * -- emergency
  18. * You can see defination for above methods at monolog documentation.
  19. *
  20. * @package cores
  21. * @author Reborn CMS Development Team
  22. **/
  23. class Log
  24. {
  25. /**
  26. * Variable for Log config items
  27. *
  28. * @var array
  29. **/
  30. public $configs = array();
  31. #public $instance = null;
  32. /**
  33. * Variable for monolog object
  34. *
  35. * @var object
  36. **/
  37. public $logger = null;
  38. /**
  39. * Default constructor method for log object
  40. * You can pass configs values shch as
  41. *
  42. * <code>
  43. * array(
  44. * 'path' => 'public/storages/applogs/',
  45. * 'file_name' => 'mylog-'Date(Y-m-d),
  46. * 'ext' => '.txt'
  47. * );
  48. * </code>
  49. *
  50. * @param string $name
  51. * @param array $configs
  52. * @return void
  53. **/
  54. public function __construct($name = 'rebornCMSLog', $configs = array())
  55. {
  56. $defaultConfigs = Config::get('app.log');
  57. // Merge Default configs and given configs
  58. $this->configs = array_merge($defaultConfigs, $configs);
  59. $this->logger = new Logger($name);
  60. $fullpath = $this->configs['path'].$this->configs['file_name'].$this->configs['ext'];
  61. $this->logger->pushHandler(new StreamHandler($fullpath, Logger::DEBUG));
  62. }
  63. /**
  64. * Get the Logger Object
  65. *
  66. * @return object
  67. */
  68. public function getLogger()
  69. {
  70. return $this->logger;
  71. }
  72. /**
  73. * Debug Log method adpater
  74. *
  75. * @param mixed $text Message you want to logging
  76. */
  77. public function debug($text)
  78. {
  79. $this->logger->addDebug($text);
  80. }
  81. /**
  82. * Info Log method adpater
  83. *
  84. * @param mixed $text Message you want to logging
  85. */
  86. public function info($text)
  87. {
  88. $this->logger->addInfo($text);
  89. }
  90. /**
  91. * Notice Log method adpater
  92. *
  93. * @param mixed $text Message you want to logging
  94. */
  95. public function notice($text)
  96. {
  97. $this->logger->addNotice($text);
  98. }
  99. /**
  100. * Warning Log method adpater
  101. *
  102. * @param mixed $text Message you want to logging
  103. */
  104. public function warning($text)
  105. {
  106. $this->logger->addWarning($text);
  107. }
  108. /**
  109. * Error Log method adpater
  110. *
  111. * @param mixed $text Message you want to logging
  112. */
  113. public function error($text)
  114. {
  115. $this->logger->addError($text);
  116. }
  117. /**
  118. * Critical Log method adpater
  119. *
  120. * @param mixed $text Message you want to logging
  121. */
  122. public function critical($text)
  123. {
  124. $this->logger->addCritical($text);
  125. }
  126. /**
  127. * Alert Log method adpater
  128. *
  129. * @param mixed $text Message you want to logging
  130. */
  131. public function alert($text)
  132. {
  133. $this->logger->addAlert($text);
  134. }
  135. /**
  136. * Emergency Log method adpater
  137. *
  138. * @param mixed $text Message you want to logging
  139. */
  140. public function emergency($text)
  141. {
  142. $this->logger->addEmergency($text);
  143. }
  144. } // END class Log