| 1 | package Tail::Tool::Plugin::GroupLines; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | # Created on: 2011-04-04 14:42:01 | ||||||||||||||||||||||||||||
| 4 | # Create by: Ivan Wills | ||||||||||||||||||||||||||||
| 5 | # $Id$ | ||||||||||||||||||||||||||||
| 6 | # $Revision$, $HeadURL$, $Date$ | ||||||||||||||||||||||||||||
| 7 | # $Revision$, $Source$, $Date$ | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use version; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use English qw/ -no_match_vars /; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use AnyEvent; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 1 | extends 'Tail::Tool::PreProcess'; | |||||||||||||||||||||||||||
| 17 | 1 | with 'Tail::Tool::RegexList'; | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 1 | our $VERSION = version->new('0.4.5'); | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 1 | has end => ( | |||||||||||||||||||||||||||
| 22 | is => 'rw', | ||||||||||||||||||||||||||||
| 23 | isa => 'Bool', | ||||||||||||||||||||||||||||
| 24 | ); | ||||||||||||||||||||||||||||
| 25 | 1 | has allow_empty => ( | |||||||||||||||||||||||||||
| 26 | is => 'rw', | ||||||||||||||||||||||||||||
| 27 | isa => 'Bool', | ||||||||||||||||||||||||||||
| 28 | default => 1, | ||||||||||||||||||||||||||||
| 29 | ); | ||||||||||||||||||||||||||||
| 30 | 1 | has files => ( | |||||||||||||||||||||||||||
| 31 | is => 'rw', | ||||||||||||||||||||||||||||
| 32 | isa => 'HashRef[HashRef]', | ||||||||||||||||||||||||||||
| 33 | ); | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | sub process { | ||||||||||||||||||||||||||||
| 36 | 0 | ▶ | my ($self, $line, $file) = @_; | ||||||||||||||||||||||||||
|
Subroutine
process: not called CC=11 SCAR=48.8
Pod
documented
| |||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 0 | ▶ | if ( !$self->files ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | 0 | $self->files({}); | |||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 0 | ▶ | my $match = grep {my $r = $_->regex; $_->enabled && $line =~ /$r/ } @{ $self->regex }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 0 | ▶ | if ( $match || $self->files->{$file->name}{show} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$match or $self->files->{$file->name}{"show"}
MC/DC0%0/2
$match or $self->files->{$file->name}{"show"}
$match
$self->files->{$file->name}{"show"}
Truth table0%0/3
A or B
A= $matchB= $self->files->{$file->name}{"show"}
| |||||||||||||||||||||||||||||
| 45 | 0 | ▶ | if ( $self->end ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | 0 | $line = "$self->files->{$file->name}{line}$line"; | |||||||||||||||||||||||||||
| 47 | 0 | $self->files->{$file->name}{line} = ''; | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | else { | ||||||||||||||||||||||||||||
| 50 | 0 | my $new_line = $self->files->{$file->name}{line}; | |||||||||||||||||||||||||||
| 51 | 0 | $self->files->{$file->name}{line} = $line; | |||||||||||||||||||||||||||
| 52 | 0 | $line = $new_line; | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | 0 | ▶ | undef $self->files->{$file->name}{watcher} if !$self->files->{$file->name}{show}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | 0 | undef $self->files->{$file->name}{show}; | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | else { | ||||||||||||||||||||||||||||
| 58 | 0 | $self->files->{$file->name}{line} .= $line; | |||||||||||||||||||||||||||
| 59 | 0 | $line = undef; | |||||||||||||||||||||||||||
| 60 | 0 | ▶ | if ( !$self->end && !$self->files->{$file->name}{watcher} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->end or $self->files->{$file->name}{"watcher"}
MC/DC0%0/2
$self->end or $self->files->{$file->name}{"watcher"}
$self->end
$self->files->{$file->name}{"watcher"}
Truth table0%0/3
A or B
A= $self->endB= $self->files->{$file->name}{"watcher"}
| |||||||||||||||||||||||||||||
| 61 | # create a timer that will cause log lines to be written 2s after | ||||||||||||||||||||||||||||
| 62 | # they are first encounted when the match method is on the start of | ||||||||||||||||||||||||||||
| 63 | # the line, other wise these lines wont be shown until the next line | ||||||||||||||||||||||||||||
| 64 | # is found which may be some time. | ||||||||||||||||||||||||||||
| 65 | 0 | ▶ | my $size = $file->size || 0; | ||||||||||||||||||||||||||
|
Condition0%0/2
$file->size || 0
MC/DC0%0/1
$file->size || 0
$file->size
Truth table0%0/2
A
A= $file->size
| |||||||||||||||||||||||||||||
| 66 | $self->files->{$file->name}{watcher} = AE::timer 2, 0, sub { | ||||||||||||||||||||||||||||
| 67 | 0 | ▶ | $self->allow_empty(1); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 68 | 0 | $self->files->{$file->name}{show} = 1; | |||||||||||||||||||||||||||
| 69 | 0 | ▶ | $file->run() if $file->size >= $size; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | 0 | }; | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 0 | ▶ | return defined $line ? ($line) : (); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 1 | 1; | |||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | __END__ | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | =head1 NAME | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | Tail::Tool::Plugin::GroupLines - Groups real lines of a log file so that other plugins treat then as one line. | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | =head1 VERSION | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | This documentation refers to Tail::Tool::Plugin::GroupLines version 0.4.5. | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | use Tail::Tool::Plugin::GroupLines; | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | # Brief but working code example(s) here showing the most common usage(s) | ||||||||||||||||||||||||||||
| 94 | # This section will be as far as many users bother reading, so make it as | ||||||||||||||||||||||||||||
| 95 | # educational and exemplary as possible. | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | Groups lines together so that they are presented as one line to other plugins. | ||||||||||||||||||||||||||||
| 101 | It does this by checking each real log file line and checking if it matches | ||||||||||||||||||||||||||||
| 102 | regex to indicate the start of a line (or if end is true the regex matches | ||||||||||||||||||||||||||||
| 103 | the end of lines). | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | An example of why you might want to do this: | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | A log file with long data dumps that span many lines may be hard to filter out | ||||||||||||||||||||||||||||
| 108 | but if those lines can be grouped together then only part of the line need | ||||||||||||||||||||||||||||
| 109 | match for all lines to be excluded. | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | =head1 SUBROUTINES/METHODS | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | =head2 C<process ($line, $file)> | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | =head1 DIAGNOSTICS | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | =head1 CONFIGURATION AND ENVIRONMENT | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | =head1 DEPENDENCIES | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | =head1 INCOMPATIBILITIES | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | =head1 BUGS AND LIMITATIONS | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | There are no known bugs in this module. | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | Please report problems to Ivan Wills (ivan.wills@gmail.com). | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | Patches are welcome. | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | Ivan Wills - (ivan.wills@gmail.com) | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | =head1 LICENSE AND COPYRIGHT | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | Copyright (c) 2011 Ivan Wills (14 Mullion Close, Hornsby Heights, NSW, Australia). | ||||||||||||||||||||||||||||
| 138 | All rights reserved. | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | This module is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||
| 141 | the same terms as Perl itself. See L<perlartistic>. This program is | ||||||||||||||||||||||||||||
| 142 | distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; | ||||||||||||||||||||||||||||
| 143 | without even the implied warranty of MERCHANTABILITY or FITNESS FOR A | ||||||||||||||||||||||||||||
| 144 | PARTICULAR PURPOSE. | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | =cut | ||||||||||||||||||||||||||||