logger.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * This file is part of Hyperf.
  5. *
  6. * @link https://www.hyperf.io
  7. * @document https://hyperf.wiki
  8. * @contact group@hyperf.io
  9. * @license https://github.com/hyperf/hyperf/blob/master/LICENSE
  10. */
  11. use function Hyperf\Support\env;
  12. $appDebug = (bool)env('APP_DEBUG', false);
  13. $handlers = $appDebug ? ['debug', 'warning', 'error'] : ['warning', 'error'];
  14. return [
  15. 'default' => [
  16. 'handlers' => $handlers
  17. ],
  18. 'debug' => [
  19. 'handler' => [
  20. 'class' => \Monolog\Handler\RotatingFileHandler::class,
  21. 'constructor' => [
  22. 'filename' => BASE_PATH . '/runtime/logs/hyperf.log',
  23. 'level' => Monolog\Logger::DEBUG,
  24. ],
  25. ],
  26. 'formatter' => [
  27. 'class' => Monolog\Formatter\LineFormatter::class,
  28. 'constructor' => [
  29. 'format' => null,
  30. 'dateFormat' => 'Y-m-d H:i:s',
  31. 'allowInlineLineBreaks' => true,
  32. ],
  33. ],
  34. ],
  35. 'warning' => [
  36. 'handler' => [
  37. 'class' => \Monolog\Handler\RotatingFileHandler::class,
  38. 'constructor' => [
  39. 'filename' => BASE_PATH . '/runtime/logs/hyperf-warning.log',
  40. 'level' => Monolog\Logger::WARNING,
  41. ],
  42. ],
  43. 'formatter' => [
  44. 'class' => Monolog\Formatter\LineFormatter::class,
  45. 'constructor' => [
  46. 'format' => null,
  47. 'dateFormat' => 'Y-m-d H:i:s',
  48. 'allowInlineLineBreaks' => true,
  49. ],
  50. ],
  51. ],
  52. 'error' => [
  53. 'handler' => [
  54. 'class' => \Monolog\Handler\RotatingFileHandler::class,
  55. 'constructor' => [
  56. 'filename' => BASE_PATH . '/runtime/logs/hyperf-error.log',
  57. 'level' => Monolog\Logger::ERROR,
  58. ],
  59. ],
  60. 'formatter' => [
  61. 'class' => Monolog\Formatter\LineFormatter::class,
  62. 'constructor' => [
  63. 'format' => null,
  64. 'dateFormat' => 'Y-m-d H:i:s',
  65. 'allowInlineLineBreaks' => true,
  66. ],
  67. ],
  68. ]
  69. ];