PageRenderTime 46ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/log4php/Appender/PhpAppender.php

https://github.com/ehutson/log4php
PHP | 66 lines | 21 code | 6 blank | 39 comment | 5 complexity | 2d0e86fd73eb360061f91f7e28f12443 MD5 | raw file
  1. <?php
  2. namespace log4php\Appender;
  3. use log4php\LoggerAppender,
  4. log4php\LoggerLoggingEvent,
  5. \log4php\LoggerLevel;
  6. /**
  7. * Licensed to the Apache Software Foundation (ASF) under one or more
  8. * contributor license agreements. See the NOTICE file distributed with
  9. * this work for additional information regarding copyright ownership.
  10. * The ASF licenses this file to You under the Apache License, Version 2.0
  11. * (the "License"); you may not use this file except in compliance with
  12. * the License. You may obtain a copy of the License at
  13. *
  14. * http://www.apache.org/licenses/LICENSE-2.0
  15. *
  16. * Unless required by applicable law or agreed to in writing, software
  17. * distributed under the License is distributed on an "AS IS" BASIS,
  18. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  19. * See the License for the specific language governing permissions and
  20. * limitations under the License.
  21. *
  22. * @package log4php
  23. */
  24. /**
  25. * Log events using php {@link PHP_MANUAL#trigger_error} function and a {@link LoggerLayoutTTCC} default layout.
  26. *
  27. * This appender has no configurable parameters.
  28. *
  29. * Levels are mapped as follows:
  30. *
  31. * - <b>level < WARN</b> mapped to E_USER_NOTICE
  32. * - <b>WARN <= level < ERROR</b> mapped to E_USER_WARNING
  33. * - <b>level >= ERROR</b> mapped to E_USER_ERROR
  34. *
  35. * An example:
  36. *
  37. * {@example ../../examples/php/appender_php.php 19}
  38. *
  39. * {@example ../../examples/resources/appender_php.properties 18}
  40. *
  41. * @version $Revision: 1166182 $
  42. * @package log4php
  43. * @subpackage appenders
  44. */
  45. class PhpAppender extends LoggerAppender
  46. {
  47. public function append(LoggerLoggingEvent $event)
  48. {
  49. if ($this->layout !== null) {
  50. $level = $event->getLevel();
  51. if ($level->isGreaterOrEqual(LoggerLevel::getLevelError())) {
  52. trigger_error($this->layout->format($event), E_USER_ERROR);
  53. } else if ($level->isGreaterOrEqual(LoggerLevel::getLevelWarn())) {
  54. trigger_error($this->layout->format($event), E_USER_WARNING);
  55. } else {
  56. trigger_error($this->layout->format($event), E_USER_NOTICE);
  57. }
  58. }
  59. }
  60. }