[SCM] libmessage-passing-perl Debian packaging branch, master, updated. debian/0.111-3-14-g44f6e88

Tomas Doran bobtfish at bobtfish.net
Mon May 6 11:56:51 UTC 2013


The following commit has been merged in the master branch:
commit 1c75a1c1b34b3412a2a562492dca65433748742f
Author: Tomas Doran <bobtfish at bobtfish.net>
Date:   Sun Apr 22 13:35:25 2012 +0100

    Initial sketch - stealing code
    from MonitoringJS

diff --git a/lib/Log/Stash/Input/STDIN.pm b/lib/Log/Stash/Input/FileTail.pm
similarity index 51%
copy from lib/Log/Stash/Input/STDIN.pm
copy to lib/Log/Stash/Input/FileTail.pm
index 4e3fd12..49fa5cd 100644
--- a/lib/Log/Stash/Input/STDIN.pm
+++ b/lib/Log/Stash/Input/FileTail.pm
@@ -1,4 +1,4 @@
-package Log::Stash::Input::STDIN;
+package Log::Stash::Input::FileTail;
 use Moose;
 use AnyEvent;
 use Try::Tiny;
@@ -6,18 +6,43 @@ use namespace::autoclean;
 
 with 'Log::Stash::Role::Input';
 
+has filename => (
+    is => 'ro',
+    isa => 'Str',
+    required => 1,
+);
+
+has _tail_handle => (
+    is => 'ro',
+    lazy => 1,
+    builder => '_build_tail_handle',
+);
+
+has tailer_pid => (
+    init_arg => undef,
+    is => 'ro',
+    writer => '_set_tailer_pid',
+);
+
+sub _build_tail_handle {
+    my $self = shift;
+    my $r;
+    my $child_pid = open($r, "-|", "tail", "-F", $self->filename)
+       // die "can't fork: $!";
+    AnyEvent->io (
+        fh => $r,
+        poll => "r",
+        cb => sub {
+            my $data = parse_from_line(scalar <$r>)
+                or return;
+            $self->on_read->($data);
+        },
+    );
+}
+
 sub BUILD {
     my $self = shift;
-    my $r; $r = AnyEvent->io(fh => \*STDIN, poll => 'r', cb => sub {
-        my $input = <STDIN>;
-        return unless defined $input;
-        chomp($input);
-        my $data = try { $self->decode($input) }
-            catch { warn $_ };
-        return unless $data;
-        $self->output_to->consume($data);
-        $r;
-    });
+    $self->_tail_handle;
 }
 
 __PACKAGE__->meta->make_immutable;
@@ -25,11 +50,11 @@ __PACKAGE__->meta->make_immutable;
 
 =head1 NAME
 
-Log::Stash::Input::STDIN - STDIN input
+Log::Stash::Input::FileTail - File tailing input
 
 =head1 SYNOPSIS
 
-    logstash --input STDIN --output STDOUT
+    logstash --input FileTail --input_options '{"filename": "/var/log/foo.log"} --output STDOUT
     {"foo": "bar"}
     {"foo":"bar"}
 
@@ -63,3 +88,4 @@ which we do not reuse any code from) is copyright 2010 Jorden Sissel.
 XX - TODO
 
 =cut
+

-- 
libmessage-passing-perl Debian packaging



More information about the Pkg-perl-cvs-commits mailing list