【问题标题】:how to parse laravel logs in fluentd如何在fluentd中解析laravel日志
【发布时间】:2019-06-10 15:28:36
【问题描述】:

请帮助我处理 GCP 中的堆栈驱动程序日志。我正在使用流利的代理将日志从服务器发送到 GCP 堆栈驱动程序日志。主要问题是我无法按级别(信息、警告、错误)拆分日志并发送正确的 fromat。 这是我的 fluentd 配置。

<source>
  @type tail
  format /^(?<message>(?<time>[^ ]*\s*[^ ]) .*)$/
  path /var/www/example.com/shared/storage/logs/laravel.*.%Y-%m-%d.log
  pos_file /var/lib/google-fluentd/pos/example-app.pos
  read_from_head true
  tag example-app
</source>

目前,一些日志正在进入堆栈驱动程序,而另一些则没有。如何正确地将 laravel 应用程序日志分配到 stackdriver?谢谢。

这是我尝试发送到 stackdriver 的几个日志示例

信息

[2019-06-10 17:41:03] production.INFO: Updated status for  Application with external id [ 123-456-789 ]. PubSub message: array (
  'message' => 
  array (
    'attributes' => 
    array (
      'event' => 'application.applied',
      'id' => '1111-222222-5555',
      'example_id' => '1234567890',
      'source' => 'projectname',
      'timestamp' => '1560181263',
    ),
    'data' => 'sldjfhskjdfnakjfhawejflaskdflawiefjalskdfoawiejfslKDFjlkfsjgaoiwefjawoiejflKJF',
    'messageId' => '123123123',
    'message_id' => '123123123',
    'publishTime' => '2019-06-10T15:41:03.282Z',
    'publish_time' => '2019-06-10T15:41:03.282Z',
  ),
  'subscription' => 'projects/some-name/subscriptions/example-prod-application',
  '/pubsub/projectname/application/12jh3g1j2h3g12h3g1j2h3123h' => '',
)

错误

[2019-06-10 17:33:05] production.ERROR: BraintreeException. account_id: 123123. 
 Declined. 
 Braintree\Result\Error[errors=, params=paymentMethod=customerId=123123, paymentMethodNonce=tokencc_bd_123123123, options=makeDefault=true, billingAddress=streetAddress=123123 E st apt 1111, locality=city, postalCode=123123, region=some-region, countryCodeAlpha2=NO, merchantId=123123123, message=Declined, verification=Braintree\Result\CreditCardVerification[status=processor_declined, cvvResponseCode=1233, avsErrorResponseCode=, avsPostalCodeResponseCode=U, =]

警告

 [2019-06-10 09:03:11] production.WARNING: projectname PubSub message validation error: Event for application with external id [ 123123123123 ] discarded because a later message was already processed. PubSub message: array (
  'message' => 
  array (
    'attributes' => 
    array (
      'event' => 'application.applied',
      'id' => '123123123',
      'projectname_id' => '123123123',
      'source' => 'some-source',
      'timestamp' => '1560150185',
    ),
    'data' => 'j1h2g3j1h2g3j1h23gj1h2g3j1h23g1j2h3g',
    'messageId' => '123123123',
    'message_id' => '123123123',
    'publishTime' => '2019-06-10T07:03:10.647Z',
    'publish_time' => '2019-06-10T07:03:10.647Z',
  ),
  'subscription' => 'projects/project-name/subscriptions/example-prod-application',
  '/pubsub/projectname/application/123123123123' => '',
)   
[2019-06-10 15:13:22] production.WARNING: Wrong account [ 123123123 ] provided for resetting password with token [ 123123123 ]. No password reset token found.

【问题讨论】:

  • 我不熟悉 laravel 日志格式。您能否发布一个我们可以从模板角度查看的未分类数据样本?
  • 是的。给我5分钟

标签: laravel ubuntu google-cloud-platform fluentd stackdriver


【解决方案1】:

对于在 GCP 中带有 fluentd 和 stackdriver 日志的 Laravel 应用程序,您可以使用以下格式的正则表达式配置:

<source>
    @type tail
    format /^\[(?<time>\d{4}-\d{1,2}-\d{1,2}\s\d{1,2}:\d{1,2}:\d{1,2})\]\s(?<context>[^ .]+.(?<severity>\w+):(?<message>.*)$)/
    # The path of the log file.
    path /var/www/example.com/shared/storage/logs/laravel-%Y-%m-%d.log
    pos_file /var/lib/google-fluentd/pos/example-app.pos
    read_from_head true
    tag example-app
</source>

我已经对此进行了测试。它的作用就像一个魅力。

【讨论】:

    【解决方案2】:

    我通过将格式更改为“无”来解决此问题

    <source>
      @type tail
      format none
      path /var/www/example.com/shared/storage/logs/laravel.*.%Y-%m-%d.log
      pos_file /var/lib/google-fluentd/pos/example-app.pos
      read_from_head true
      tag example-app
    </source>
    

    【讨论】:

      猜你喜欢
      • 2017-05-18
      • 2019-10-20
      • 1970-01-01
      • 2017-02-06
      • 2020-08-07
      • 1970-01-01
      • 2022-08-22
      • 2018-06-19
      • 2017-10-21
      相关资源
      最近更新 更多