Skip to content

Instantly share code, notes, and snippets.

@tyler
Last active December 17, 2015 16:49
Show Gist options
  • Save tyler/5641994 to your computer and use it in GitHub Desktop.
Save tyler/5641994 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
use strict;
use warnings;
use JLog::Writer;
use JLog::Reader;
use Compress::Zlib;
use Getopt::Long;
use Fcntl;
my $compressed;
my $count = 1;
my $jlog_path;
GetOptions("z" => \$compressed,
"n=i" => \$count,
"path=s" => \$jlog_path);
print STDERR "jlog_path=$jlog_path\n";
print STDERR "compressed=$compressed\n";
$SIG{'INT'} = 'cleanup';
sub cleanup {
my $queue_writer = JLog::Writer->new($jlog_path, O_CREAT);
$queue_writer->open;
$queue_writer->remove_subscriber('jlogtail');
$queue_writer->close;
exit();
}
my $queue_writer = JLog::Writer->new($jlog_path, O_CREAT);
$queue_writer->open;
$queue_writer->add_subscriber('jlogtail');
$queue_writer->close;
my $queue_reader = JLog::Reader->new($jlog_path);
$queue_reader->open('jlogtail');
for (my $i = 0; $i < $count; $i++) {
my $msg = $queue_reader->read;
if ($compressed) {
$msg = Compress::Zlib::memGunzip($msg);
}
print "$msg\n";
}
$queue_reader->close;
cleanup();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment