laravel5日志设置篇(3/3) – 精确到微秒及日志输出位置记录

想要实现的功能

  • 记录日志输出时的时间精度到微秒
  • 记录日志输出时程序执行位置(方法/行数)
  • 记录进程ID

例如:

  • app.log
[2017-10-22 10:13:57.833504] production.INFO: -- Startup {"method":"GET","uri":"/v1/stocks"} {"pid":7124,"line":"App\\Bootstrap\\ApplicationLog->startupLog:66"}
[2017-10-22 10:13:57.898702] production.INFO: get stocks info  {"pid":7124,"line":"App\\Http\\Controllers\\StocksController->index:66"}
[2017-10-22 10:13:57.903274] production.INFO: -- Shutdown {"time":"70.371[ms]","memory":"2048[kb]"} {"pid":7124,"line":"App\\Bootstrap\\ApplicationLog->handleShutdownLog:81"}

Continue reading

laravel5日志设置篇(2/3) – 记录sql日志

想要实现的功能

  • 获取laravel运行时执行的sql语句
  • sql相关的日志保存到指定文件(sql.log)
  • 接口访问与artisan 命令日志分开保存

例如

  • sql.log
[2017-10-21 22:27:42] production.DEBUG: select count(*) as aggregate from `stocks_input` where `stocks_input`.`deleted_at` is null; {"time":0.55} 
[2017-10-21 22:27:42] production.DEBUG: select * from `stocks_input` where `stocks_input`.`deleted_at` is null order by `created_at` desc limit 10 offset 0; {"time":0.84} 
[2017-10-21 22:27:42] production.DEBUG: select * from `goods` where `goods`.`id` = 1 limit 1; {"time":0.74} 
  • cli.sql.log
[2017-10-21 22:28:15] production.DEBUG: select * from `goods` where `goods`.`id` = 1 limit 1; {"time":0.76} 
[2017-10-21 22:28:15] production.DEBUG: select * from `regions` where `regions`.`id` = 110102 limit 1; {"time":0.87} 
[2017-10-21 22:28:15] production.DEBUG: select * from `regions` where `regions`.`id` = 110000 limit 1; {"time":0.81} 

Continue reading

laravel5日志设置篇(1/3) – 记录开始和结束日志

想要实现的功能

记录Application的开始和结束日志
– 开始日志: URL请求或命令行记录
– 结束日志: 处理时间和内存使用峰值记录

例如:

[2017-10-19 23:06:00] local.INFO: -- Startup {"command":"php artisan list"} 
[2017-10-19 23:06:00] local.INFO: -- Shutdown {"time":"36.955[ms]","memory":"10[mb]"} 
[2017-10-19 23:11:37] local.INFO: -- Startup {"method":"GET","uri":"/v1/stocks"} 
[2017-10-19 23:11:37] local.INFO: -- Shutdown {"time":"21.765[ms]","memory":"4096[kb]"} 

Continue reading