Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.3KB

  1. <?php
  2. namespace Friendica\Util\Logger;
  3. use Monolog\Handler;
  4. use Monolog\Logger;
  5. /**
  6. * Simple handler for Friendica developers to use for deeper logging
  7. *
  8. * If you want to debug only interactions from your IP or the IP of a remote server for federation debug,
  9. * you'll use Logger::develop() for the duration of your work, and you clean it up when you're done before submitting your PR.
  10. */
  11. class FriendicaDevelopHandler extends Handler\AbstractHandler
  12. {
  13. /**
  14. * @var string The IP of the developer who wants to debug
  15. */
  16. private $developerIp;
  17. /**
  18. * @param string $developerIp The IP of the developer who wants to debug
  19. * @param int $level The minimum logging level at which this handler will be triggered
  20. * @param bool $bubble Whether the messages that are handled can bubble up the stack or not
  21. */
  22. public function __construct($developerIp, $level = Logger::DEBUG, $bubble = true)
  23. {
  24. parent::__construct($level, $bubble);
  25. $this->developerIp = $developerIp;
  26. }
  27. /**
  28. * {@inheritdoc}
  29. */
  30. public function handle(array $record)
  31. {
  32. if (!$this->isHandling($record)) {
  33. return false;
  34. }
  35. /// Just in case the remote IP is the same as the developer IP log the output
  36. if (!is_null($this->developerIp) && $_SERVER['REMOTE_ADDR'] != $this->developerIp)
  37. {
  38. return false;
  39. }
  40. return false === $this->bubble;
  41. }
  42. }