| Log-Agent documentation | Contained in the Log-Agent distribution. |
Log::Agent::Tag - formats caller information
Intended to be inherited from
This class is meant to be inherited by all the classes implementing a log message tag.
A message tag is a little string that is either appended or prepended to all log messages.
For instance, and oversimplifying a bit, a tag meant to be prepended will be inserted in front of the current log message, separated by separator, which defaults to a single space:
+------------+-----------+---------------------------------+ | tag string | separator | current log message | +------------+-----------+---------------------------------+
This operation is called tag insertion. The whole string then becomes the current log message, and can be the target of another tag insertion.
The reality is a little bit more complex, to allow successive tags to be prepended or appended in the order they are specified, and not in reverse order as they would be if naively implemented. See Log::Agent::Message for the exact semantics of append() and prepend() operations.
This section documents the interface provided to heirs, in case you wish to implement your own tag class.
Initialization routine that should be called by all heirs during creation to initialize the common attributes.
When true, the tag is meant to be appended to the log message. Otherwise, it is prepended.
The name of this tag. It is meant to provide by-name access to tags, check
whether a given tag is recorded, etc... The names "caller" and "priority"
are architecturally defined to refer to Log::Agent::Tag::Caller and
Log::Agent::Tag::Priority objects.
NOTE: Currently unused by any client code.
The sperating string inserted between the tag and the log message.
It defaults to " " if not specified, i.e. left to undef when
calling _init().
A deferred routine, to be implemented by heirs.
Returns the tag string only, without the separator, since its exact placement
depends on the value of the postfix attribute.
Insert this tag withing the Log::Agent::Message message, according
to the tag specifications (placement, separator). Calls string() to produce
the tag string.
This routine is frozen and should not be redefined by heirs.
Tagging classes define via their string() routine what is the string
to be used as a tag. The insertion of the tag within the log message
is done via a frozen routine from the Log::Agent::Tag ancestor.
The following classes are provided by Log::Agent:
Log::Agent::Tag::CallbackThe string() routine invokes a user-supplied callback, given as a
Callback object. You need the Callback module from CPAN if you
wish to use this class.
Log::Agent::Tag::CallerUsed internally to compute the caller and format it according to user specifications.
Log::Agent::Tag::PriorityUsed internally to format message priorities and add them to the log messages.
Log::Agent::Tag::StringDefines a constant tagging string that should be added in all the log messages, e.g. a web session ID.
Raphael Manfredi <Raphael_Manfredi@pobox.com>
Log::Agent::Message(3).
| Log-Agent documentation | Contained in the Log-Agent distribution. |
# # $Id: Tag.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: Tag.pm,v $ # Revision 1.1 2002/03/09 16:01:37 wendigo # New maintainer # # Revision 0.2.1.2 2001/03/31 10:02:18 ram # patch7: fixed =over to add explicit indent level # # Revision 0.2.1.1 2001/03/13 18:45:12 ram # patch2: created # # $EndLog$ # use strict; ######################################################################## package Log::Agent::Tag; # # ->make # # Creation routine. # sub make { my $self = bless {}, shift; require Carp; Carp::confess("deferred"); } # # Attribute access # sub postfix { $_[0]->{'postfix'} } sub name { $_[0]->{'name'} } sub separator { $_[0]->{'separator'} } # # ->_init # # Initialization routine for common attributes: # # postfix if true, appends tag to message, otherwise prepends # name the tag name # separator the string to use before or after tag (defaults to " ") # # Called by each creation routine in heirs. # sub _init { my $self = shift; my ($name, $postfix, $separator) = @_; $separator = " " unless defined $separator; $self->{name} = $name; $self->{postfix} = $postfix; $self->{separator} = $separator; return; } # # ->string -- deferred # # Build tag string. # Must be implemented by heirs. # sub string { require Carp; Carp::confess("deferred"); } # # ->insert -- frozen # # Merge string into the log message, according to our configuration. # sub insert { my $self = shift; my ($str) = @_; # A Log::Agent::Message object my $string = $self->string; my $separator = $self->separator; # # Merge into the Log::Agent::Message object string. # if ($self->postfix) { $str->append($separator . $string); } else { $str->prepend($string . $separator); } return; } 1; # for "require" __END__