<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Jon Schutz Technical Notes and Recommendations &#187; Software Development</title>
	<atom:link href="http://notes.jschutz.net/topics/software-development/feed/" rel="self" type="application/rss+xml" />
	<link>http://notes.jschutz.net</link>
	<description>Useful snippets technical info and recommendations</description>
	<lastBuildDate>Thu, 24 Jun 2010 07:07:40 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Perl client for Facebook&#8217;s scribe logging software</title>
		<link>http://notes.jschutz.net/2009/04/perl-client-for-facebooks-scribe-logging-software/</link>
		<comments>http://notes.jschutz.net/2009/04/perl-client-for-facebooks-scribe-logging-software/#comments</comments>
		<pubDate>Wed, 29 Apr 2009 04:13:57 +0000</pubDate>
		<dc:creator>jon</dc:creator>
				<category><![CDATA[Perl]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://notes.jschutz.net/?p=109</guid>
		<description><![CDATA[Scribe is a log aggregator, developed at Facebook and released as open source.  Scribe is built on Thrift, a cross-language RPC type platform, and therefore it is possible to use scribe with any of the Thrift-supported languages.  Whilst Perl is one of the supported languages, there is little in the way of working [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://developers.facebook.com/scribe/" rel="nofollow">Scribe</a> is a log aggregator, developed at Facebook and released as open source.  Scribe is built on <a href="http://incubator.apache.org/thrift/" rel="nofollow">Thrift</a>, a cross-language RPC type platform, and therefore it is possible to use scribe with any of the Thrift-supported languages.  Whilst Perl is one of the supported languages, there is little in the way of working examples, so here&#8217;s how I did it:</p>
<ol>
<li> Install Thrift.
<li> Build and install FB303 perl modules
<pre>
  cd thrift/contrib/fb303
  # Edit if/fb303.thrift and add the line 'namespace perl Facebook.FB303' after the other namespace declarations
  thrift --gen perl if/fb303.thrift
  sudo cp -a gen-perl/ /usr/local/lib/perl5/site_perl/5.10.0 # or wherever you keep your site perl
</pre>
<p>This creates the modules Facebook::FB303::Constants, Facebook::FB303::FacebookService and Facebook::FB303::Types.
</li>
<li> Install Scribe.
<li> Build and install Scribe perl modules
<pre>
  cd scribe
  # Edit if/scribe.thrift and add 'namespace perl Scribe.Thrift' after the other namespace declarations
  thrift -I /path/to/thrift/contrib/ --gen perl scribe.thrift
  sudo cp -a gen-perl/Scribe /usr/local/lib/perl5/site_perl/5.10.0/ # or wherever
</pre>
</li>
<p>This creates the modules Scribe::Thrift::Constants, Scribe::Thrift::scribe, Scribe::Thrift::Types.</p>
<ol>
<p>Here is an example program that uses the client (reading one line at a time from stdin and sending to a scribe instance running locally on port 1465):</p>
<pre>
#! /usr/bin/perl

use Scribe::Thrift::scribe;
use Thrift::Socket;
use Thrift::FramedTransport;
use Thrift::BinaryProtocol;
use strict;
use warnings;

my $host = 'localhost';
my $port = 1465;
my $cat = $ARGV[0] || 'test';

my $socket = Thrift::Socket->new($host, $port);
my $transport = Thrift::FramedTransport->new($socket);
my $proto = Thrift::BinaryProtocol->new($transport);

my $client = Scribe::Thrift::scribeClient->new($proto, $proto);
my $le = Scribe::Thrift::LogEntry->new({ category => $cat });

$transport->open();

while (my $line = <>) {
    $le->message($line);
    my $result = $client->Log([ $le ]);
    if ($result == Scribe::Thrift::ResultCode::TRY_LATER) {
	print STDERR "TRY_LATER\n";
    }
    elsif ($result != Scribe::Thrift::ResultCode::OK) {
	print STDERR "Unknown result code: $result\n";
    }
}

$transport->close();
</pre>
<p><b>UPDATE</b> Log::Dispatch::Scribe is now available on CPAN.  Also works with Log::Log4perl.  Note though, you still need to install Thrift and Scribe perl modules as described above.</p>
]]></content:encoded>
			<wfw:commentRss>http://notes.jschutz.net/2009/04/perl-client-for-facebooks-scribe-logging-software/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
