yg - log line filter, like \G of MySQL
$ yg [options] FILE ... or $ cat apache_log | yg [option] options: -p, --parser parser(default: apache-combined) -d, --delimiter the delimiter of log line(default: tab) NOTE: if you set options -p and -d, it will use -d, -p option is ignored -n, --number if you specify delimiter and -n, then show number points -m, --match show log lines only if a keyword matches -re, --regexp show log lines only if regular expression matches -i, --ignore-case regexp option: ignore case distinctions -r, --raw also show raw log lines -t, --through ignore yg command, output only raw log lines --digest show digest of raw log string -h, --help show this help message -V, --version show version
parse Apache Combined logs, show logs vertically with labels of element
$ yg apache_commbined_log
parse Apache Error logs, show logs vertically with labels of element
$ yg -p apache-error apache_error_log
parse TAB-delimited logs, show logs vertically
$ yg -d tab_delimited_log
parse TAB-delimited logs, show logs vertically with number labels
$ yg -d -n tab_delimited_log
parse SPACE-delimited logs, show logs vertically
$ yg -d space space_delimited_log
tailed log
$ tail -f apache_commbined_log | yg
yg is a log viewer(filter) to show log lines vertically.
yg
When you check apache logs, I guess you do like this
$ cat apache_log 127.0.0.1 - - [30/Sep/2012:12:34:56 +0900] "GET /foo HTTP/1.0" 200 123 "http://example.com/foo" "Mozilla/5.0" 127.0.0.1 - - [30/Sep/2012:12:34:57 +0900] "GET /bar HTTP/1.0" 301 124 "http://example.com/bar" "Mozilla/5.1"
If you use yg, log lines are showed like below:
$ yg apache_log ******************** 1 ******************** Host: 127.0.0.1 Ident: - Authuser: - Date: 30/Sep/2012:12:34:56 +0900 Request: GET /foo HTTP/1.0 Status: 200 Bytes: 123 Referer: http://example.com/foo UserAgent: Mozilla/5.0 ******************** 2 ******************** Host: 127.0.0.1 Ident: - Authuser: - Date: 30/Sep/2012:12:34:57 +0900 Request: GET /bar HTTP/1.0 Status: 200 Bytes: 124 Referer: http://example.com/bar UserAgent: Mozilla/5.1
easier for understanding.
Of course, yg can work for like below.
$ cat apache_log | yg
yg command supports few formats of log. And you can write custom parser of App::YG.
Above sample uses App::YG::Apache::Combined. It is default parser. If you want to view other format logs, you should specify --parser option.
--parser
$ cat apache-error-log | yg --parser apache-error
Then yg uses App::YG::Apache::Error to parse log lines.
$ cat apache-error-log | yg --parser apache-error ******************** 1 ******************** Date: Sat Oct 06 17:34:17 2012 Log_Level: error Client: 127.0.0.1 Message: File does not exist: /var/www/html/favicon.ico
App::YG has below parsers.
for apache combined log
for apache common log
for apache error log
for nginx main log
App::YG is designed to be easily extensible. You might want to write a custom log parser. Each parser is easy to write one.
For example:
package App::YG::MyApp::Log; use strict; use warnings; sub parse { my $line = shift; $line =~ m!^DATE:([^\t]+)\t([^\t]+)\tMSG:(.+)$! or warn "failed to parse line: '$line'\n"; return [ $1 || '', $2 || '', $3 || '', ]; } sub labels { return [qw/ Date Level Message /]; }
Parser class must have 2 methods parser and labels. Both methods must return array reference. Let's look at the anatomy of App::YG::* modules. And check test codes in t/parser/*/*.t.
parser
labels
Dai Okabayashi <bayashi@cpan.org>
App::YG
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic.
To install App::YG, copy and paste the appropriate command in to your terminal.
cpanm
cpanm App::YG
CPAN shell
perl -MCPAN -e shell install App::YG
For more information on module installation, please visit the detailed CPAN module installation guide.