TestLoggerExceptionDemo.php 832 B

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. namespace Tests\Dev;
  3. use Tests\TestCase;
  4. use UCore\Helper\Logger;
  5. /**
  6. * 测试Logger::exception格式化演示
  7. */
  8. class TestLoggerExceptionDemo extends TestCase
  9. {
  10. /**
  11. * 测试新的异常日志格式
  12. */
  13. public function testNewLoggerExceptionFormat()
  14. {
  15. try {
  16. // 故意触发一个异常
  17. throw new \Exception("这是一个测试异常,用于演示新的日志格式");
  18. } catch (\Exception $e) {
  19. // 使用新的Logger::exception方法记录异常
  20. Logger::exception('测试新的异常日志格式', $e, [
  21. 'test_data' => '这是测试数据',
  22. 'user_id' => 12345,
  23. 'action' => 'format_test'
  24. ]);
  25. }
  26. // 测试通过
  27. $this->assertTrue(true);
  28. }
  29. }