ThinkPHP logs

Last Updated: Jul 05, 2017

ThinkPHP is a Web application development framework based on the PHP language.

ThinkPHP sample log

The following logging method is used in ThinkPHP:

  1. <?php
  2. Think\Log::record('D model class not found for method instantiation' );
  3. ?>

The printed log using this method is shown below:

  1. [ 2016-05-11T21:03:05+08:00 ] 30.9.181.163 /index.php
  2. INFO: [ app_init ] --START--
  3. INFO: Run Behavior\BuildLiteBehavior [ RunTime:0.000014s ]
  4. INFO: [ app_init ] --END-- [ RunTime:0.000091s ]
  5. INFO: [ app_begin ] --START--
  6. INFO: Run Behavior\ReadHtmlCacheBehavior [ RunTime:0.000038s ]
  7. INFO: [ app_begin ] --END-- [ RunTime:0.000076s ]
  8. INFO: [ view_parse ] --START--
  9. INFO: Run Behavior\ParseTemplateBehavior [ RunTime:0.000068s ]
  10. INFO: [ view_parse ] --END-- [ RunTime:0.000104s ]
  11. INFO: [ view_filter ] --START--
  12. INFO: Run Behavior\WriteHtmlCacheBehavior [ RunTime:0.000032s ]
  13. INFO: [ view_filter ] --END-- [ RunTime:0.000062s ]
  14. INFO: [ app_end ] --START--
  15. INFO: Run Behavior\ShowPageTraceBehavior [ RunTime:0.000032s ]
  16. INFO: [ app_end ] --END-- [ RunTime:0.000070s ]
  17. ERR: D model class not found for method instantiation

ThinkPHP log collection by Log Service

ThinkPHP logs are multiline logs in varying modes. The following fields can be extracted from these logs: time, IP address of the visitor, accessed URL, and printed message. Because the message mode is not fixed, the message is packaged into a field containing multiple lines of information.

In Log Service, select multiline mode and fill in the following regular expression at the beginning of the line.

  1. \[\s\d+-\d+-\w+:\d+:\d+\+\d+:\d+\s.*

Regular expression:

  1. \[\s(\d+-\d+-\w+:\d+:\d+)[^:]+:\d+\s]\s+(\S+)\s(\S+)\s+(.*)

Time expression:

  1. %Y-%m-%dT%H:%M:%S
Thank you! We've received your feedback.