FluentdFormatterTest.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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\Logger;
  12. use Monolog\Test\TestCase;
  13. class FluentdFormatterTest extends TestCase
  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(Logger::WARNING);
  34. $record['datetime'] = new \DateTimeImmutable("@0");
  35. $formatter = new FluentdFormatter();
  36. $this->assertEquals(
  37. '["test",0,{"message":"test","extra":[],"level":300,"level_name":"WARNING"}]',
  38. $formatter->format($record)
  39. );
  40. }
  41. /**
  42. * @covers Monolog\Formatter\FluentdFormatter::format
  43. */
  44. public function testFormatWithTag()
  45. {
  46. $record = $this->getRecord(Logger::ERROR);
  47. $record['datetime'] = new \DateTimeImmutable("@0");
  48. $formatter = new FluentdFormatter(true);
  49. $this->assertEquals(
  50. '["test.error",0,{"message":"test","extra":[]}]',
  51. $formatter->format($record)
  52. );
  53. }
  54. }