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

/classes/firephp/log/console.php

http://github.com/jerfowler/KO3_FirePHP
PHP | 153 lines | 104 code | 4 blank | 45 comment | 8 complexity | e3287aad0a1f453f2447eb9469f3647d MD5 | raw file
  1. <?php defined('SYSPATH') or die('No direct script access.');
  2. /**
  3. * FirePHP log writer.
  4. */
  5. class FirePHP_Log_Console extends Kohana_Log_Writer {
  6. protected $_firephp;
  7. // List of excluded types
  8. protected $_excluded;
  9. // Format for console entries
  10. protected $_format;
  11. /**
  12. * Creates a new FirePHP logger.
  13. *
  14. * @param string config array
  15. * @return void
  16. */
  17. public function __construct(array $config=NULL) {
  18. $this->_firephp = FirePHP_Profiler::instance();
  19. if (isset($config)) $this->_firephp->set_config($config);
  20. $this->_format = $this->_firephp->get_config('log.console.format', 'time --- type: body');
  21. $this->_excluded = $this->_firephp->get_config('log.console.exclude');
  22. }
  23. /**
  24. * Writes each of the messages to FirePHP
  25. *
  26. * @param array messages
  27. * @return void
  28. */
  29. public function write(array $messages) {
  30. // Set the log line format
  31. $format = $this->_format;
  32. foreach ($messages as $message) { // Write each message into the log file
  33. if (isset($this->_excluded) AND in_array($message['type'], $this->_excluded)) continue;
  34. switch($message['type'])
  35. {
  36. /**
  37. * Firebug LOG level
  38. */
  39. case 'FirePHP::LOG':
  40. if (is_array($message['body']))
  41. {
  42. $label = Arr::path($message, 'body.label', '');
  43. $object = Arr::path($message, 'body.object', $message['body']);
  44. $this->_firephp->log($object, $label);
  45. }
  46. else
  47. {
  48. $this->_firephp->log(strtr($format, $message));
  49. }
  50. break;
  51. /**
  52. * Firebug INFO level
  53. */
  54. case 'FirePHP::INFO':
  55. if (is_array($message['body']))
  56. {
  57. $label = Arr::path($message, 'body.label', '');
  58. $object = Arr::path($message, 'body.object', $message['body']);
  59. $this->_firephp->info($object, $label);
  60. }
  61. else
  62. {
  63. $this->_firephp->info(strtr($format, $message));
  64. }
  65. break;
  66. /**
  67. * Firebug WARN level
  68. */
  69. case 'FirePHP::WARN':
  70. if (is_array($message['body']))
  71. {
  72. $label = Arr::path($message, 'body.label', '');
  73. $object = Arr::path($message, 'body.object', $message['body']);
  74. $this->_firephp->warn($object, $label);
  75. }
  76. else
  77. {
  78. $this->_firephp->warn(strtr($format, $message));
  79. }
  80. break;
  81. /**
  82. * Firebug ERROR level
  83. */
  84. case 'FirePHP::ERROR':
  85. if (is_array($message['body']))
  86. {
  87. $label = Arr::path($message, 'body.label', '');
  88. $object = Arr::path($message, 'body.object', $message['body']);
  89. $this->_firephp->error($object, $label);
  90. }
  91. else
  92. {
  93. $this->_firephp->error(strtr($format, $message));
  94. }
  95. break;
  96. /**
  97. * Dumps a variable to firebug's server panel
  98. */
  99. case 'FirePHP::DUMP':
  100. if (is_array($message['body']))
  101. {
  102. $key = Arr::path($message, 'body.key', '');
  103. $variable = Arr::path($message, 'body.variable', $message['body']);
  104. $this->_firephp->dump($key, $variable);
  105. }
  106. else
  107. {
  108. $this->_firephp->log(strtr($format, $message));
  109. }
  110. break;
  111. /**
  112. * Displays a stack trace in firebug console
  113. */
  114. case 'FirePHP::TRACE';
  115. $this->_firephp->trace(strtr($format, $message));
  116. break;
  117. /**
  118. * Displays an table in firebug console
  119. */
  120. case 'FirePHP::TABLE':
  121. if (is_array($message['body']))
  122. {
  123. $label = Arr::path($message, 'body.label', '');
  124. $table = Arr::path($message, 'body.table', '');
  125. $this->_firephp->table($label, $table);
  126. }
  127. else
  128. {
  129. $this->_firephp->log(strtr($format, $message));
  130. }
  131. break;
  132. /**
  133. * Starts a group in firebug console
  134. */
  135. case 'FirePHP::GROUP_START';
  136. $this->_firephp->group(strtr($format, $message));
  137. break;
  138. /**
  139. * Ends a group in firebug console
  140. */
  141. case 'FirePHP::GROUP_END';
  142. $this->_firephp->groupEnd();
  143. break;
  144. default:
  145. $this->_firephp->log(strtr($format, $message));
  146. }
  147. }
  148. }
  149. } // End Kohana_Log_File