logging.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <?php
  2. /*
  3. * This file is part of the Jiannei/lumen-api-starter.
  4. *
  5. * (c) Jiannei <longjian.huang@foxmail.com>
  6. *
  7. * This source file is subject to the MIT license that is bundled
  8. * with this source code in the file LICENSE.
  9. */
  10. use Jiannei\Logger\Laravel\MongoLogger;
  11. use Monolog\Handler\NullHandler;
  12. use Monolog\Handler\StreamHandler;
  13. use Monolog\Handler\SyslogUdpHandler;
  14. return [
  15. /*
  16. |--------------------------------------------------------------------------
  17. | Default Log Channel
  18. |--------------------------------------------------------------------------
  19. |
  20. | This option defines the default log channel that gets used when writing
  21. | messages to the logs. The name specified in this option should match
  22. | one of the channels defined in the "channels" configuration array.
  23. |
  24. */
  25. 'default' => env('LOG_CHANNEL', 'stack'),
  26. /*
  27. |--------------------------------------------------------------------------
  28. | Log Channels
  29. |--------------------------------------------------------------------------
  30. |
  31. | Here you may configure the log channels for your application. Out of
  32. | the box, Laravel uses the Monolog PHP logging library. This gives
  33. | you a variety of powerful log handlers / formatters to utilize.
  34. |
  35. | Available Drivers: "single", "daily", "slack", "syslog",
  36. | "errorlog", "monolog",
  37. | "custom", "stack"
  38. |
  39. */
  40. 'channels' => [
  41. 'stack' => [
  42. 'driver' => 'stack',
  43. 'channels' => ['daily'],
  44. ],
  45. 'single' => [
  46. 'driver' => 'single',
  47. 'path' => storage_path('logs/lumen.log'),
  48. 'level' => 'debug',
  49. ],
  50. 'daily' => [
  51. 'driver' => 'daily',
  52. 'path' => storage_path('logs/lumen.log'),
  53. 'level' => 'debug',
  54. 'days' => 14,
  55. ],
  56. 'slack' => [
  57. 'driver' => 'slack',
  58. 'url' => env('LOG_SLACK_WEBHOOK_URL'),
  59. 'username' => 'Lumen Log',
  60. 'emoji' => ':boom:',
  61. 'level' => 'critical',
  62. ],
  63. 'papertrail' => [
  64. 'driver' => 'monolog',
  65. 'level' => 'debug',
  66. 'handler' => SyslogUdpHandler::class,
  67. 'handler_with' => [
  68. 'host' => env('PAPERTRAIL_URL'),
  69. 'port' => env('PAPERTRAIL_PORT'),
  70. ],
  71. ],
  72. 'stderr' => [
  73. 'driver' => 'monolog',
  74. 'handler' => StreamHandler::class,
  75. 'with' => [
  76. 'stream' => 'php://stderr',
  77. ],
  78. ],
  79. 'syslog' => [
  80. 'driver' => 'syslog',
  81. 'level' => 'debug',
  82. ],
  83. 'errorlog' => [
  84. 'driver' => 'errorlog',
  85. 'level' => 'debug',
  86. ],
  87. 'null' => [
  88. 'driver' => 'monolog',
  89. 'handler' => NullHandler::class,
  90. ],
  91. 'mongo' => [
  92. 'driver' => 'custom', // 此处必须为 `custom`
  93. 'via' => MongoLogger::class, // 当 `driver` 设置为 custom 时,使用 `via` 配置项所指向的工厂类创建 logger
  94. 'channel' => env('LOG_MONGODB_CHANNEL', 'mongo'),
  95. 'level' => env('LOG_MONGODB_LEVEL', 'debug'), // 日志级别
  96. 'separate' => env('LOG_MONGODB_SEPARATE', false), // false,daily,monthly,yearly
  97. 'host' => env('LOG_MONGODB_HOST', config('database.connections.mongodb.host')),
  98. 'port' => env('LOG_MONGODB_PORT', config('database.connections.mongodb.port')),
  99. 'username' => env('LOG_MONGODB_USERNAME', config('database.connections.mongodb.username')),
  100. 'password' => env('LOG_MONGODB_PASSWORD', config('database.connections.mongodb.password')),
  101. 'database' => env('LOG_MONGODB_DATABASE', config('database.connections.mongodb.database')),
  102. ],
  103. ],
  104. 'enum' => \App\Repositories\Enums\LogEnum::class,
  105. 'query' => [
  106. 'enabled' => env('LOG_QUERY', false),
  107. 'message' => 'query',
  108. 'connection' => env('LOG_QUERY_CONNECTION', config('queue.default')), // queue connection
  109. 'queue' => env('LOG_QUERY_QUEUE', 'default'), // queue name
  110. // Only record queries that are slower than the following time
  111. // Unit: milliseconds
  112. 'slower_than' => 0,
  113. ],
  114. 'request' => [
  115. 'enabled' => env('LOG_REQUEST', false),
  116. 'message' => 'request',
  117. 'connection' => env('LOG_REQUEST_CONNECTION', config('queue.default')), // queue connection
  118. 'queue' => env('LOG_REQUEST_QUEUE', 'default'), // queue name
  119. ],
  120. 'listener' => [
  121. 'requestArrivedListener' => \ZhMead\Logger\Laravel\Listeners\RequestArrivedListener::class,
  122. 'requestHandledListener' => \ZhMead\Logger\Laravel\Listeners\RequestHandledListener::class,
  123. ],
  124. // 'job' => \ZhMead\Logger\Laravel\Jobs\LogJob::class,
  125. 'job' => \App\Jobs\LogJob::class,
  126. 'guard' => 'admins',
  127. ];