如何解析流利的laravel日志

时间:2019-06-10 15:28:36

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

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

<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.

2 个答案:

答案 0 :(得分:1)

对于在GCP中具有流利的&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>

我已经测试过了。它的工作就像一种魅力。

答案 1 :(得分:0)

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

<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>
相关问题