xail - tail for winners
xail is a super lightweight Ruby DSL for building simple stream/log analysis tools.
A simple log viewer: logview.xail.rb
:
#!/usr/bin/env xail
group('fatal') {
contains 'fatal'
bell
}
group('error') {
contains 'error', 'exception'
red
bold
}
group('warning') {
contains 'warn'
yellow
}
You can then run it directly:
$ ./logview.xail.rb
And it will accept input on stdin or a filename on the command line.
You can directly specify:
Filters
There are filters and compound filters. A filter takes a line from a stream and performs some action, potentially altering the stream, or terminating the flow. Compound filters take a stream and also a set of subfilters. These generally implement flow control.
Stdout is the ultimate consumer of the strings, unless they've been filtered.
Compound Filters
cascade
-- stream the result of first subfilter that streamscomposition
-- applies each subfilter on the stream of the preceding subfilter, streaming the final resultand
-- streams the original if all subfilters streamor
-- streams the original if any subfilter streamsnot
-- streams the original if no subfilters stream
Matching Filters
contains
-- streams the original if any of the parameters are includedreplace
-- mutates the stream
Alerting Filters
execute
executes a command, replacing{}
with the line contentbell
rings a terminal bell (if possible)
Styling Filters
black
,red
,green
,yellow
,blue
,magenta
,cyan
,white
-- adjust foreground coloronblack
,onred
,ongreen
,onyellow
,onblue
,onmagenta
,oncyan
,onwhite
-- adjust background colorbold
,blink
,underscore
,negative
,dark
-- apply effects to the text
Special Filters
sample
-- samples the stream, only printing at the rate requestedstop
-- stops processing of this stream and continues with the nextcount
-- [todo] computes the rate of the stream for display (need UI aspect)
Custom Filters
You can easily develop your own filters. Either as an anonymous block: