JsonFormatter.php 779 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. /*
  3. * This file is part of the Monolog package.
  4. *
  5. * (c) Jordi Boggiano <j.boggiano@seld.be>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Monolog\Formatter;
  11. use Monolog\Logger;
  12. /**
  13. * Encodes whatever record data is passed to it as json
  14. *
  15. * This can be useful to log to databases or remote APIs
  16. *
  17. * @author Jordi Boggiano <j.boggiano@seld.be>
  18. */
  19. class JsonFormatter implements FormatterInterface
  20. {
  21. /**
  22. * {@inheritdoc}
  23. */
  24. public function format(array $record)
  25. {
  26. return json_encode($record);
  27. }
  28. /**
  29. * {@inheritdoc}
  30. */
  31. public function formatBatch(array $records)
  32. {
  33. return json_encode($records);
  34. }
  35. }