Log::Log4perl::Appender::Stomp - Log messages via STOMP


Log-Log4perl-Appender-Stomp documentation Contained in the Log-Log4perl-Appender-Stomp distribution.

Index


Code Index:

NAME

Top

Log::Log4perl::Appender::Stomp - Log messages via STOMP

VERSION

Top

version 1.000

SYNOPSIS

Top

    use Log::Log4perl;

    # Default options are in $conf
    my $conf = qq(
        log4perl.category = WARN, STOMP

        log4perl.appender.STOMP                          = Log::Log4perl::Appender::Stomp
        log4perl.appender.STOMP.hostname                 = localhost
        log4perl.appender.STOMP.port                     = 61613
        log4perl.appender.STOMP.topic_name               = log
        log4perl.appender.STOMP.layout                   = PatternLayout
        log4perl.appender.STOMP.layout.ConversionPattern = %d %-5p %m%n
    );

    Log::Log4perl::init(\$conf);

    Log::Log4perl->get_logger("blah")->debug("...");

DESCRIPTION

Top

This allows you to send log messages via the Streaming Text Orientated Messaging Protocol to a message broker that supports STOMP, such as Apache's ActiveMQ.

This makes use of topics in ActiveMQ so that multiple consumers can receive the log messages from multiple producers. It takes a similar approach as syslog does but uses ActiveMQ to do the message handling.

CONFIGURATION AND ENVIRONMENT

Top

You can change:

* hostname
* port
* topic_name

In the Log::Log4perl configuration.

Log::Log4perl
Net::Stomp
ActiveMQ http://activemq.apache.org

SUPPORT

Top

You can find documentation for this module with the perldoc command.

    perldoc Log::Log4perl::Appender::Stomp

You can also look for information at:

* RT: CPAN's request tracker: http://rt.cpan.org/NoAuth/Bugs.html?Dist=Log-Log4perl-Appender-Stomp
* AnnoCPAN: Annotated CPAN documentation: http://annocpan.org/dist/Log-Log4perl-Appender-Stomp
* CPAN Ratings: http://cpanratings.perl.org/d/Log-Log4perl-Appender-Stomp
* Search CPAN: http://search.cpan.org/dist/Log-Log4perl-Appender-Stomp

AUTHOR

Top

  Adam Flott <adam@npjh.com>

COPYRIGHT AND LICENSE

Top


Log-Log4perl-Appender-Stomp documentation Contained in the Log-Log4perl-Appender-Stomp distribution.

package Log::Log4perl::Appender::Stomp;
our $VERSION = '1.000';

# ABSTRACT: Log messages via STOMP

use warnings;
use strict;

use Net::Stomp;

our @ISA = qw(Log::Log4perl::Appender);

sub new {
    my ($class, %options) = @_;

    my $self = {
        'name'       => $options{'name'}       || 'unknown',
        'hostname'   => $options{'hostname'}   || 'localhost',
        'port'       => $options{'port'}       || 61613,
        'topic_name' => $options{'topic_name'} || 'log',
        'connection' => undef,
        %options
    };

    bless($self, $class);

    return $self;
}

sub log { ## no critic
    my ($self, %params) = @_;

    my $stomp = $self->{'connection'};

    unless ($stomp) {

        $stomp = Net::Stomp->new(
            {
                'hostname' => $self->{'hostname'},
                'port'     => $self->{'port'}
            }
        );

        unless ($stomp->connect({ 'login' => 'noauth', 'passcode' => 'supportyet' })) {
            die('Connection to ', $self->{'hostname'}, ':', $self->{'port'}, " failed: $!");
        }

        $self->{'connection'} = $stomp;
    }

    return $stomp->send(
        {
            'destination' => sprintf('/topic/%s', $self->{'topic_name'}),
            'body'        => $params{'message'}
        }
    );
}

sub DESTROY {
    my ($self) = @_;

    if ($self->{'connection'}) {
        $self->{'connection'}->disconnect();
    }

    return;
}

1;




__END__