FluentdFormatterTest.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php declare(strict_types=1);
  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\Level;
  12. use Monolog\Test\MonologTestCase;
  13. class FluentdFormatterTest extends MonologTestCase
  14. {
  15. /**
  16. * @covers Monolog\Formatter\FluentdFormatter::__construct
  17. * @covers Monolog\Formatter\FluentdFormatter::isUsingLevelsInTag
  18. */
  19. public function testConstruct()
  20. {
  21. $formatter = new FluentdFormatter();
  22. $this->assertEquals(false, $formatter->isUsingLevelsInTag());
  23. $formatter = new FluentdFormatter(false);
  24. $this->assertEquals(false, $formatter->isUsingLevelsInTag());
  25. $formatter = new FluentdFormatter(true);
  26. $this->assertEquals(true, $formatter->isUsingLevelsInTag());
  27. }
  28. /**
  29. * @covers Monolog\Formatter\FluentdFormatter::format
  30. */
  31. public function testFormat()
  32. {
  33. $record = $this->getRecord(Level::Warning, datetime: new \DateTimeImmutable("@0"));
  34. $formatter = new FluentdFormatter();
  35. $this->assertEquals(
  36. '["test",0,{"message":"test","context":[],"extra":[],"level":300,"level_name":"WARNING"}]',
  37. $formatter->format($record)
  38. );
  39. }
  40. /**
  41. * @covers Monolog\Formatter\FluentdFormatter::format
  42. */
  43. public function testFormatWithTag()
  44. {
  45. $record = $this->getRecord(Level::Error, datetime: new \DateTimeImmutable("@0"));
  46. $formatter = new FluentdFormatter(true);
  47. $this->assertEquals(
  48. '["test.error",0,{"message":"test","context":[],"extra":[]}]',
  49. $formatter->format($record)
  50. );
  51. }
  52. }