| 1 | package Toadfarm::Command::tail; | ||||||||||||
| 2 | 6 | ▶ | use Mojo::Base 'Mojolicious::Command'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 3 | 6 | ▶ | use Time::HiRes 'usleep'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | |||||||||||||
| 5 | 6 | ▶ | use constant BUF_SIZE => 4096; # can probably be any number | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | 6 | ▶ | use constant TAIL_EXE => $ENV{TAIL_EXE} || 'tail'; | ||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=7.1
Condition50%1/2
$ENV{'TAIL_EXE'} || 'tail'
MC/DC0%0/1
$ENV{'TAIL_EXE'} || 'tail'
$ENV{'TAIL_EXE'}
Truth table50%1/2
A
A= $ENV{'TAIL_EXE'}
| |||||||||||||
| 7 | |||||||||||||
| 8 | 6 | our $VERSION = '0.01'; | |||||||||||
| 9 | |||||||||||||
| 10 | 6 | has description => 'Toadfarm: Tail the log file'; | |||||||||||
| 11 | |||||||||||||
| 12 | 0 | ▶ | sub run { shift->_tail(@_) } | ||||||||||
|
Subroutine
run: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 13 | |||||||||||||
| 14 | 0 | ▶ | sub _end { | ||||||||||
|
Subroutine
_end: not called CC=3 SCAR=24.8
| |||||||||||||
| 15 | 0 | my ($self, $exit, $message) = @_; | |||||||||||
| 16 | 0 | ▶ | say $message if $message; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 17 | 0 | ▶ | return $exit if $ENV{TOADFARM_NO_EXIT}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 18 | 0 | exit $exit; | |||||||||||
| 19 | } | ||||||||||||
| 20 | |||||||||||||
| 21 | 0 | ▶ | sub _tail { | ||||||||||
|
Subroutine
_tail: not called CC=6 SCAR=37.4
| |||||||||||||
| 22 | 0 | my $self = shift; | |||||||||||
| 23 | 0 | my $log_file = $self->app->log->path; | |||||||||||
| 24 | |||||||||||||
| 25 | 0 | ▶ | return $self->_end(2, 'Unknown log file.') unless $log_file; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 26 | 0 | ▶ | exec TAIL_EXE, @_, $log_file if @_; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 27 | |||||||||||||
| 28 | # open and go to end of file | ||||||||||||
| 29 | 0 | ▶ | open my $LOG, '<', $log_file or die "Cannot tail $log_file: $!\n"; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 30 | 0 | my $pos = -s $log_file; | |||||||||||
| 31 | 0 | warn "\$ tail -f $log_file\n"; | |||||||||||
| 32 | 0 | ▶ | $SIG{$_} = sub { print "\n"; $self->_end(0) } | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||
| 33 | 0 | for qw(INT TERM); | |||||||||||
| 34 | |||||||||||||
| 35 | 0 | while (1) { | |||||||||||
| 36 | 0 | seek $LOG, $pos, 0; | |||||||||||
| 37 | 0 | ▶ | while (<$LOG>) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 38 | 0 | local $| = 1; | |||||||||||
| 39 | 0 | print $_; | |||||||||||
| 40 | 0 | $pos = tell $LOG; | |||||||||||
| 41 | } | ||||||||||||
| 42 | 0 | usleep 500e3; | |||||||||||
| 43 | } | ||||||||||||
| 44 | |||||||||||||
| 45 | 0 | return $self->_exit; | |||||||||||
| 46 | } | ||||||||||||
| 47 | |||||||||||||
| 48 | 6 | 1; | |||||||||||
| 49 | |||||||||||||
| 50 | =encoding utf8 | ||||||||||||
| 51 | |||||||||||||
| 52 | =head1 NAME | ||||||||||||
| 53 | |||||||||||||
| 54 | Toadfarm::Command::tail - Tail the toadfarm log file | ||||||||||||
| 55 | |||||||||||||
| 56 | =head1 DESCRIPTION | ||||||||||||
| 57 | |||||||||||||
| 58 | L<Toadfarm::Command::tail> is a command for tailing the log file used | ||||||||||||
| 59 | by the L<Toadfarm> application. | ||||||||||||
| 60 | |||||||||||||
| 61 | =head1 SYNOPSIS | ||||||||||||
| 62 | |||||||||||||
| 63 | $ /path/to/script.pl tail | ||||||||||||
| 64 | $ /path/to/script.pl tail -n 10 -f -q | ||||||||||||
| 65 | |||||||||||||
| 66 | The tail command will start tailig from the end of file. Any options | ||||||||||||
| 67 | passed after the "tail" command will issue C<tail> to be started | ||||||||||||
| 68 | instead, with the given arguments. | ||||||||||||
| 69 | |||||||||||||
| 70 | =head1 ATTRIBUTES | ||||||||||||
| 71 | |||||||||||||
| 72 | =head2 description | ||||||||||||
| 73 | |||||||||||||
| 74 | Short description of command, used for the command list. | ||||||||||||
| 75 | |||||||||||||
| 76 | =head1 METHODS | ||||||||||||
| 77 | |||||||||||||
| 78 | =head2 run | ||||||||||||
| 79 | |||||||||||||
| 80 | Run command. | ||||||||||||
| 81 | |||||||||||||
| 82 | =head1 COPYRIGHT AND LICENSE | ||||||||||||
| 83 | |||||||||||||
| 84 | Copyright (C) 2014, Jan Henning Thorsen | ||||||||||||
| 85 | |||||||||||||
| 86 | This program is free software, you can redistribute it and/or modify it under | ||||||||||||
| 87 | the terms of the Artistic License version 2.0. | ||||||||||||
| 88 | |||||||||||||
| 89 | =head1 AUTHOR | ||||||||||||
| 90 | |||||||||||||
| 91 | Jan Henning Thorsen - C<jhthorsen@cpan.org> | ||||||||||||
| 92 | |||||||||||||
| 93 | =cut | ||||||||||||