Log::Agent::Channel - ancestor class for all Log::Agent channels


Log-Agent documentation Contained in the Log-Agent distribution.

Index


Code Index:

NAME

Top

Log::Agent::Channel - ancestor class for all Log::Agent channels

SYNOPSIS

Top

 @Log::Agent::Channel::XXX::ISA = qw(Log::Agent::Channel);

DESCRIPTION

Top

The Log::Agent::Channel class is the root class from which all Log::Agent channels inherit. It is a deferred class, meaning that it cannot be instantiated directly. All the deferred routines need to be implemented by its heirs to form a valid driver.

Internally, the various Log::Agent::Driver objects create Log::Agent::Channel instances for each logging channel defined at driver creation time. The channels are therefore architecturally hidden within Log::Agent, since this module only provides redefined mappings for the various logxxx() routines (logerr(), logwarn(), logdie(), etc...).

However, this does not mean that channel classes cannot be used externally: the Log::Agent::Logger extension makes Log::Agent::Channel objects architecturally visible, thereby offering an application-level logging API that can be redirected to various places transparently for the application.

CHANNEL LIST

Top

The following channels are currently made available by Log::Agent. More channels can be defined by the Log::Agent::Logger extension:

Log::Agent::Channel::File

This channel writes logs to files, defined by their path or via a magical opening sequence such as "|cmd". See Log::Agent::Channel::File.

Log::Agent::Channel::Handle

This channel writes logs to an already opened descriptor, as specified by its file handle: an IO::Handle object, or a GLOB reference such as \*FILE. See Log::Agent::Channel::Handle.

Log::Agent::Channel::Syslog

This channel redirects logs to the syslogd(8) daemon, which will then handle the dispatching to various logfiles, based on its own configuration. See Log::Agent::Channel::Syslog.

INTERFACE

Top

You need not read this section if you're only using Log::Agent. However, if you wish to implement another channel, then this section might be of interest.

The following routines are deferred and therefore need to be defined by the heir:

write($priority, $logstring)

Emit the log entry held in $logstring, at priority $priority. A trailing "\n" is added to the $logstring, if needed (i.e. if the physical entity does not do it already, like syslog does).

The $priority argument must be a valid syslog priority, i.e. one of the following strings: "emerg", "alert", "crit", "err", "warning", "notice", "info", "debug".

The $logstring may not really be a plain string. It can actually be a Log::Agent::Message object with an overloaded stringification routine, so the illusion should be complete.

close

Close the channel.

make

This is the creation routine. Its signature varies for each channel, naturally.

AUTHOR

Top

Raphael Manfredi <Raphael_Manfredi@pobox.com>

SEE ALSO

Top

Log::Agent::Channel::File(3), Log::Agent::Channel::Handle(3), Log::Agent::Channel::Syslog(3), Log::Agent::Logger(3).


Log-Agent documentation Contained in the Log-Agent distribution.

#
# $Id: Channel.pm,v 1.1 2002/03/09 16:01:37 wendigo Exp $
#
#  Copyright (c) 1999, Raphael Manfredi
#  
#  You may redistribute only under the terms of the Artistic License,
#  as specified in the README file that comes with the distribution.
#
# HISTORY
# $Log: Channel.pm,v $
# Revision 1.1  2002/03/09 16:01:37  wendigo
# New maintainer
#
# Revision 0.2.1.2  2001/04/11 15:51:10  ram
# patch8: added hyperlinks within POD to ease web browsing of manpage
#
# Revision 0.2.1.1  2001/03/31 10:00:11  ram
# patch7: fixed =over to add explicit indent level
#
# Revision 0.2  2000/11/06 19:30:32  ram
# Baseline for second Alpha release.
#
# $EndLog$
#

use strict;

########################################################################
package Log::Agent::Channel;

#
# Ancestor for all Log::Agent logging channels.
#

#
# is_deferred
#
# Report routine as being deferred
#
sub is_deferred {
	require Carp;
	Carp::confess("deferred");
}

#
# ->make			-- deferred
#
# Creation routine.
#
sub make {
	&is_deferred;
}

#
# ->write_fn		-- frozen
#
# Message is a CODE ref, call routine to generate it, then perform write.
# Extra arguments after CODE ref are passed back to the routine.
#
sub write_fn {
	my $self = shift;
	my ($priority, $fn) = splice(@_, 0, 2);
	my $msg = &$fn(@_);
	$self->write($priority, $msg);
}

#
# ->write			-- deferred
#
# Physical writing of the message with the said priority.
#
sub write {
	my $self = shift;
	my ($priority, $msg) = @_;
	&is_deferred;
}

#
# ->close			-- deferred
#
sub close {
	my $self = shift;
	&is_deferred;
}

1;	# for require
__END__