$ cat access.log
time:2015-09-06T05:58:05+09:00 method:POST uri:/foo/bar?token=xxx&uuid=1234 status:200 size:12 apptime:0.057
time:2015-09-06T06:00:43+09:00 method:GET uri:/foo/bar status:400 size:15 apptime:-
time:2015-09-06T06:00:43+09:00 method:GET uri:/foo/bar/5xx status:504 size:15 apptime:60.000
# Ruby 2.6 より前でも動くように Hash#to_h にブロックを渡さない書き方をする。
$ cat access.log | ruby -e 'ARGF.read.each_line { |line| hash = line.split("\s").map { |item| item.split(":", 2) }.to_h; puts hash.values_at("method", "uri", "status").join(" ") }'
POST /foo/bar?token=xxx&uuid=1234 200
GET /foo/bar 400
GET /foo/bar/5xx 504
More than 3 years have passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme