PageRenderTime 52ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/log4php/layouts/LoggerLayoutTTCC.php

https://github.com/daithi-coombes/wp-comment-flowdock
PHP | 201 lines | 74 code | 25 blank | 102 comment | 7 complexity | ccc042a97ae2a83cc72d997e2cf2cb74 MD5 | raw file
  1. <?php
  2. /**
  3. * Licensed to the Apache Software Foundation (ASF) under one or more
  4. * contributor license agreements. See the NOTICE file distributed with
  5. * this work for additional information regarding copyright ownership.
  6. * The ASF licenses this file to You under the Apache License, Version 2.0
  7. * (the "License"); you may not use this file except in compliance with
  8. * the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. *
  18. * @package log4php
  19. */
  20. /**
  21. * TTCC layout format consists of <b>t</b>ime, <b>t</b>hread, <b>c</b>ategory and nested
  22. * diagnostic <b>c</b>ontext information, hence the name.
  23. *
  24. * <p>Each of the four fields can be individually enabled or
  25. * disabled. The time format depends on the <b>DateFormat</b> used.</p>
  26. *
  27. * <p>If no dateFormat is specified it defaults to '%c'.
  28. * See php {@link PHP_MANUAL#date} function for details.</p>
  29. *
  30. * Configurable parameters for this layout are:
  31. * - {@link $threadPrinting} (true|false) enable/disable pid reporting.
  32. * - {@link $categoryPrefixing} (true|false) enable/disable logger category reporting.
  33. * - {@link $contextPrinting} (true|false) enable/disable NDC reporting.
  34. * - {@link $microSecondsPrinting} (true|false) enable/disable micro seconds reporting in timestamp.
  35. * - {@link $dateFormat} (string) set date format. See php {@link PHP_MANUAL#date} function for details.
  36. *
  37. * An example how to use this layout:
  38. *
  39. * {@example ../../examples/php/layout_ttcc.php 19}<br>
  40. *
  41. * {@example ../../examples/resources/layout_ttcc.properties 18}<br>
  42. *
  43. * The above would print:<br>
  44. * <samp>02:28 [13714] INFO root - Hello World!</samp>
  45. *
  46. * @version $Revision: 1302503 $
  47. * @package log4php
  48. * @subpackage layouts
  49. *
  50. * @deprecated LoggerLayout TTCC is deprecated and will be removed in a future release. Please use
  51. * LoggerLayoutPattern instead.
  52. */
  53. class LoggerLayoutTTCC extends LoggerLayout {
  54. // Internal representation of options
  55. protected $threadPrinting = true;
  56. protected $categoryPrefixing = true;
  57. protected $contextPrinting = true;
  58. protected $microSecondsPrinting = true;
  59. /**
  60. * @var string date format. See {@link PHP_MANUAL#strftime} for details
  61. */
  62. protected $dateFormat = '%c';
  63. /**
  64. * Constructor
  65. *
  66. * @param string date format
  67. * @see dateFormat
  68. */
  69. public function __construct($dateFormat = '') {
  70. $this->warn("LoggerLayout TTCC is deprecated and will be removed in a future release. Please use LoggerLayoutPattern instead.");
  71. if (!empty($dateFormat)) {
  72. $this->dateFormat = $dateFormat;
  73. }
  74. return;
  75. }
  76. /**
  77. * The <b>ThreadPrinting</b> option specifies whether the name of the
  78. * current thread is part of log output or not. This is true by default.
  79. */
  80. public function setThreadPrinting($threadPrinting) {
  81. $this->setBoolean('threadPrinting', $threadPrinting);
  82. }
  83. /**
  84. * @return boolean Returns value of the <b>ThreadPrinting</b> option.
  85. */
  86. public function getThreadPrinting() {
  87. return $this->threadPrinting;
  88. }
  89. /**
  90. * The <b>CategoryPrefixing</b> option specifies whether {@link Category}
  91. * name is part of log output or not. This is true by default.
  92. */
  93. public function setCategoryPrefixing($categoryPrefixing) {
  94. $this->setBoolean('categoryPrefixing', $categoryPrefixing);
  95. }
  96. /**
  97. * @return boolean Returns value of the <b>CategoryPrefixing</b> option.
  98. */
  99. public function getCategoryPrefixing() {
  100. return $this->categoryPrefixing;
  101. }
  102. /**
  103. * The <b>ContextPrinting</b> option specifies log output will include
  104. * the nested context information belonging to the current thread.
  105. * This is true by default.
  106. */
  107. public function setContextPrinting($contextPrinting) {
  108. $this->setBoolean('contextPrinting', $contextPrinting);
  109. }
  110. /**
  111. * @return boolean Returns value of the <b>ContextPrinting</b> option.
  112. */
  113. public function getContextPrinting() {
  114. return $this->contextPrinting;
  115. }
  116. /**
  117. * The <b>MicroSecondsPrinting</b> option specifies if microseconds infos
  118. * should be printed at the end of timestamp.
  119. * This is true by default.
  120. */
  121. public function setMicroSecondsPrinting($microSecondsPrinting) {
  122. $this->setBoolean('microSecondsPrinting', $microSecondsPrinting);
  123. }
  124. /**
  125. * @return boolean Returns value of the <b>MicroSecondsPrinting</b> option.
  126. */
  127. public function getMicroSecondsPrinting() {
  128. return $this->microSecondsPrinting;
  129. }
  130. public function setDateFormat($dateFormat) {
  131. $this->setString('dateFormat', $dateFormat);
  132. }
  133. /**
  134. * @return string
  135. */
  136. public function getDateFormat() {
  137. return $this->dateFormat;
  138. }
  139. /**
  140. * In addition to the level of the statement and message, the
  141. * returned string includes time, thread, category.
  142. * <p>Time, thread, category are printed depending on options.
  143. *
  144. * @param LoggerLoggingEvent $event
  145. * @return string
  146. */
  147. public function format(LoggerLoggingEvent $event) {
  148. $timeStamp = (float)$event->getTimeStamp();
  149. $format = strftime($this->dateFormat, (int)$timeStamp);
  150. if ($this->microSecondsPrinting) {
  151. $usecs = floor(($timeStamp - (int)$timeStamp) * 1000);
  152. $format .= sprintf(',%03d', $usecs);
  153. }
  154. $format .= ' ';
  155. if ($this->threadPrinting) {
  156. $format .= '['.getmypid().'] ';
  157. }
  158. $level = $event->getLevel();
  159. $format .= $level.' ';
  160. if($this->categoryPrefixing) {
  161. $format .= $event->getLoggerName().' ';
  162. }
  163. if($this->contextPrinting) {
  164. $ndc = $event->getNDC();
  165. if($ndc != null) {
  166. $format .= $ndc.' ';
  167. }
  168. }
  169. $format .= '- '.$event->getRenderedMessage();
  170. $format .= PHP_EOL;
  171. return $format;
  172. }
  173. public function ignoresThrowable() {
  174. return true;
  175. }
  176. }