r10227 - in /branches/upstream/liblog-agent-logger-perl: ./ current/ current/t/
vdanjean at users.alioth.debian.org
vdanjean at users.alioth.debian.org
Sat Dec 1 12:05:02 UTC 2007
Author: vdanjean
Date: Sat Dec 1 12:05:02 2007
New Revision: 10227
URL: http://svn.debian.org/wsvn/?sc=1&rev=10227
Log:
[svn-inject] Installing original source of liblog-agent-logger-perl
Added:
branches/upstream/liblog-agent-logger-perl/
branches/upstream/liblog-agent-logger-perl/current/
branches/upstream/liblog-agent-logger-perl/current/ChangeLog
branches/upstream/liblog-agent-logger-perl/current/Logger.pm
branches/upstream/liblog-agent-logger-perl/current/MANIFEST
branches/upstream/liblog-agent-logger-perl/current/Makefile.PL
branches/upstream/liblog-agent-logger-perl/current/README
branches/upstream/liblog-agent-logger-perl/current/patchlevel.h
branches/upstream/liblog-agent-logger-perl/current/t/
branches/upstream/liblog-agent-logger-perl/current/t/basic.t
branches/upstream/liblog-agent-logger-perl/current/t/caller.t
branches/upstream/liblog-agent-logger-perl/current/t/code.pl
branches/upstream/liblog-agent-logger-perl/current/t/priority.t
branches/upstream/liblog-agent-logger-perl/current/t/tags.t
Added: branches/upstream/liblog-agent-logger-perl/current/ChangeLog
URL: http://svn.debian.org/wsvn/branches/upstream/liblog-agent-logger-perl/current/ChangeLog?rev=10227&op=file
==============================================================================
--- branches/upstream/liblog-agent-logger-perl/current/ChangeLog (added)
+++ branches/upstream/liblog-agent-logger-perl/current/ChangeLog Sat Dec 1 12:05:02 2007
@@ -1,0 +1,29 @@
+Wed Apr 11 18:19:42 MEST 2001 Raphael Manfredi <Raphael_Manfredi at pobox.com>
+
+. Description:
+
+ Now relies on Getargs::Long for argument parsing.
+
+ New -caller argument to customize caller tracing, with the
+ ability to dynamically change settings via set_caller_info().
+
+ New -priority argument to customize priority tracing, with
+ the ability to dynamically change settings via set_priority_info().
+
+ New -tags argument to add user-defined tags in the logs.
+
+ Must use Log::Agent 0.208 or better, since we rely on a specific
+ feature for priority tracing.
+
+ Now tests proper sprintf semantics in log arguments, i.e. that
+ something like
+
+ $log->error("this is message #%d", 5)
+
+ works as advertised.
+
+Fri Nov 3 10:28:17 MET 2000 Raphael Manfredi <Raphael_Manfredi at pobox.com>
+
+. Description
+
+ Initial revision 0.1.
Added: branches/upstream/liblog-agent-logger-perl/current/Logger.pm
URL: http://svn.debian.org/wsvn/branches/upstream/liblog-agent-logger-perl/current/Logger.pm?rev=10227&op=file
==============================================================================
--- branches/upstream/liblog-agent-logger-perl/current/Logger.pm (added)
+++ branches/upstream/liblog-agent-logger-perl/current/Logger.pm Sat Dec 1 12:05:02 2007
@@ -1,0 +1,586 @@
+#
+# $Id: Logger.pm,v 0.1.1.1 2001/04/11 16:13:53 ram Exp $
+#
+# Copyright (c) 2000, 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: Logger.pm,v $
+# Revision 0.1.1.1 2001/04/11 16:13:53 ram
+# patch1: now relies on Getargs::Long for argument parsing
+# patch1: new -caller argument to customize caller tracing
+# patch1: new -priority argument to customize priority tracing
+# patch1: new -tags argument to add user-defined tags in the logs
+# patch1: updated version number
+#
+# Revision 0.1 2000/11/06 20:14:13 ram
+# Baseline for first Alpha release.
+#
+# $EndLog$
+#
+
+use strict;
+
+########################################################################
+package Log::Agent::Logger;
+
+use vars qw($VERSION);
+
+$VERSION = '0.101';
+
+use Log::Agent;
+use Log::Agent::Formatting qw(tag_format_args);
+use Log::Agent::Priorities qw(:LEVELS level_from_prio prio_from_level);
+use Getargs::Long qw(ignorecase);
+
+BEGIN {
+ no strict 'refs';
+ my %fn;
+ %fn = (
+ 'emerg' => q/['emerg', EMERG]/,
+ 'emergency' => q/['emerg', EMERG]/,
+ 'alert' => q/['alert', ALERT]/,
+ 'crit' => q/['crit', CRIT]/,
+ 'critical' => q/['crit', CRIT]/,
+ 'err' => q/['err', ERROR]/,
+ 'error' => q/['err', ERROR]/,
+ 'warning', => q/['warning', WARN]/,
+ 'warn', => q/['warning', WARN]/,
+ 'notice' => q/['notice', NOTICE]/,
+ 'info' => q/['info', INFO]/,
+ 'debug' => q/['debug', DEBUG]/,
+ ) unless defined &emergency;
+ for my $sub (keys %fn) {
+ my $prilvl = $fn{$sub};
+ *$sub = eval qq{
+ sub {
+ my \$self = shift;
+ if (ref \$_[0] eq 'CODE') {
+ \$self->_log_fn($prilvl, \\\@_);
+ } else {
+ \$self->_log($prilvl, \\\@_);
+ }
+ return;
+ }
+ };
+ }
+}
+
+#
+# ->make
+#
+# Creation routine.
+#
+# Attributes (and switches that set them):
+#
+# -channel logging channel
+# -max_prio maximum priority logged (included)
+# -min_prio minimum priority logged (included)
+# -caller customizes the caller information to be inserted
+# -priority customizes the priority information to be inserted
+# -tags list of user-defined tags to add to messages
+#
+sub make {
+ my $self = bless {}, shift;
+ my ($caller, $priority, $tags);
+
+ (
+ $self->{channel}, $self->{max_prio}, $self->{min_prio},
+ $caller, $priority, $tags
+ ) = xgetargs(@_,
+ -channel => 'Log::Agent::Channel',
+ -max_prio => ['s', DEBUG],
+ -min_prio => ['s', EMERG],
+ -caller => ['ARRAY'],
+ -priority => ['ARRAY'],
+ -tags => ['ARRAY'],
+ );
+
+ #
+ # Always use numeric priorities internally
+ #
+
+ $self->{max_prio} = level_from_prio($self->{max_prio})
+ if $self->{max_prio} =~ /^\D+$/;
+
+ $self->{min_prio} = level_from_prio($self->{min_prio})
+ if $self->{min_prio} =~ /^\D+$/;
+
+ $self->set_priority_info(@$priority) if defined $priority;
+ $self->set_caller_info(@$caller) if defined $caller;
+
+ #
+ # Handle -tags => [ <list of Log::Agent::Tag objects> ]
+ #
+
+ if (defined $tags) {
+ my $type = "Log::Agent::Tag";
+ if (grep { !ref $_ || !$_->isa($type) } @$tags) {
+ require Carp;
+ Carp::croak("Argument -tags must supply list of $type objects");
+ }
+ if (@$tags) {
+ require Log::Agent::Tag_List;
+ $self->{tags} = Log::Agent::Tag_List->make(@$tags);
+ }
+ }
+
+ return $self;
+}
+
+#
+# Attribute access
+#
+
+sub channel { $_[0]->{channel} }
+sub max_prio { $_[0]->{max_prio} }
+sub min_prio { $_[0]->{min_prio} }
+sub tags { $_[0]->{tags} || $_[0]->_init_tags }
+
+sub max_prio_str { prio_from_level $_[0]->{max_prio} }
+sub min_prio_str { prio_from_level $_[0]->{min_prio} }
+
+sub set_max_prio
+ { $_[0]->{max_prio} = $_[1] =~ /^\D+$/ ? level_from_prio($_[1]) : $_[1] }
+sub set_min_prio
+ { $_[0]->{min_prio} = $_[1] =~ /^\D+$/ ? level_from_prio($_[1]) : $_[1] }
+
+#
+# ->close
+#
+# Close underlying channel, and detach from it.
+#
+sub close {
+ my $self = shift;
+ my $channel = $self->{channel};
+ return unless defined $channel; # Already closed
+ $self->{channel} = undef;
+ $channel->close;
+}
+
+#
+# ->set_caller_info
+#
+# Change settings of caller tag information.
+# Giving an empty list removes caller tagging.
+#
+sub set_caller_info {
+ my $self = shift;
+
+ unless (@_) {
+ delete $self->{caller};
+ return;
+ }
+
+ require Log::Agent::Tag::Caller;
+ $self->{caller} = Log::Agent::Tag::Caller->make(-offset => 4, @_);
+ return;
+}
+
+#
+# ->set_priority_info
+#
+# Change settings of caller tag information.
+# Giving an empty list removes priority tagging.
+#
+sub set_priority_info {
+ my $self = shift;
+ my @info = @_;
+
+ unless (@info) {
+ delete $self->{priority};
+ return;
+ }
+
+ $self->{priority} = \@info; # For objects created in _prio_tag()
+
+ #
+ # When settings are changes, we need to clear the cache of priority
+ # tags generated by _prio_tag().
+ #
+
+ $self->{prio_cache} = {}; # Internal for ->_prio_tag()
+ return;
+}
+
+
+#
+# ->_log
+#
+# Emit log at given priority, if within priority bounds.
+#
+sub _log {
+ my ($self, $prilvl) = splice(@_, 0, 2);
+ my $channel = $self->{channel};
+ return unless defined $channel; # Closed
+
+ #
+ # Prune call if we're not within bounds.
+ # $prilvl is seomthing like ["error", ERROR].
+ #
+
+ my $lvl = $prilvl->[1];
+ return if $lvl > $self->{max_prio} || $lvl < $self->{min_prio};
+
+ #
+ # Issue logging.
+ #
+
+ my $priority = $self->_prio_tag(@$prilvl) if defined $self->{priority};
+
+ $channel->write($prilvl->[0],
+ tag_format_args($self->{caller}, $priority, $self->{tags}, @_));
+
+ return;
+}
+
+#
+# ->_log_fn
+#
+# Emit log at given priority, if within priority bounds.
+# The logged string needs to be computed by calling back a routine.
+#
+sub _log_fn {
+ my ($self, $prilvl) = splice(@_, 0, 2);
+ my $channel = $self->{channel};
+ return unless defined $channel; # Closed
+
+ #
+ # Prune call if we're not within bounds.
+ # $prilvl is seomthing like ["error", ERROR].
+ #
+
+ my $lvl = $prilvl->[1];
+ return if $lvl > $self->{max_prio} || $lvl < $self->{min_prio};
+
+ #
+ # Issue logging.
+ #
+
+ my $fn = shift @{$_[0]};
+ my $msg = &$fn(@{$_[0]});
+ return unless length $msg; # Null messsage, don't log
+
+ my $priority = $self->_prio_tag(@$prilvl) if defined $self->{priority};
+
+ $channel->write($prilvl->[0],
+ tag_format_args($self->{caller}, $priority, $self->{tags}, [$msg]));
+
+ return;
+}
+
+#
+# _prio_tag
+#
+# Returns Log::Agent::Tag::Priority message that is suitable for tagging
+# at this priority/level, if configured to log priorities.
+#
+# Objects are cached into `prio_cache'.
+#
+sub _prio_tag {
+ my $self = shift;
+ my ($prio, $level) = @_;
+ my $ptag = $self->{prio_cache}->{$prio, $level};
+ return $ptag if defined $ptag;
+
+ require Log::Agent::Tag::Priority;
+
+ #
+ # Common attributes (formatting, postfixing, etc...) are held in
+ # the `priorities' attribute. We add the priority/level here.
+ #
+
+ $ptag = Log::Agent::Tag::Priority->make(
+ -priority => $prio,
+ -level => $level,
+ @{$self->{priority}}
+ );
+
+ return $self->{prio_cache}->{$prio, $level} = $ptag;
+}
+
+#
+# ->_init_tags
+#
+# Initialize the `tags' attribute the first time it is requested
+# Returns its value.
+#
+sub _init_tags {
+ my $self = shift;
+ require Log::Agent::Tag_List;
+ return $self->{tags} = Log::Agent::Tag_List->make();
+}
+
+1; # for require
+__END__
+
+=head1 NAME
+
+Log::Agent::Logger - a logging interface
+
+=head1 SYNOPSIS
+
+ require Log::Agent::Logger;
+
+ my $log = Log::Agent::Logger->make(
+ -channel => $chan,
+ -max_prio => 'info',
+ -min_prio => 'emerg',
+ );
+
+ $log->error("can't open file %s: $!", $file);
+ $log->warning("can't open file: $!");
+
+=head1 DESCRIPTION
+
+The C<Log::Agent::Logger> class defines a generic interface for application
+logging. It must not be confused with the interface provided by Log::Agent,
+which is meant to be used by re-usable modules that do not wish to commit
+on a particular logging method, so that they remain true building blocks.
+
+By contrast, C<Log::Agent::Logger> explicitely requests an object to be used,
+and that object must commit upon the logging channel to be used, at creation
+time.
+
+Optionally, minimum and maximum priority levels may be defined (and changed
+dynamically) to limit the messages to effectively log, depending on the
+advertised priority. The standard syslog(3) priorities are used.
+
+=head1 CHANNEL LIST
+
+The following channels are available:
+
+=head2 Standard Log::Agent Channels
+
+Those channels are documented in L<Log::Agent::Channel>.
+
+=head2 Other Channels
+
+Future C<Log::Agent::Logger> extension will extend the set of available
+channels.
+
+=head1 INTERFACE
+
+=head2 Creation Routine
+
+The creation routine is called C<make> and takes the following switches:
+
+=over 4
+
+=item C<-caller> => [ I<parameters> ]
+
+Request that caller information (relative to the ->log() call) be part
+of the log message. The given I<parameters> are handed off to the
+creation routine of C<Log::Agent::Tag::Caller> and are documented there.
+
+I usually say something like:
+
+ -caller => [ -display => '($sub/$line)', -postfix => 1 ]
+
+which I find informative enough. On occasion, I found myself using more
+complex sequences. See L<Log::Agent::Tag::Caller>.
+
+=item C<-channel>
+
+This defines the C<Log::Agent::Channel> to be used for logging.
+Please refer to L<Log::Agent::Channel> for details, and in particular
+to get a list of pre-defined logging channels.
+
+=item C<-min_prio>
+
+Defines the minimum priority to be logged (included). Defaults to "emerg".
+
+=item C<-max_prio>
+
+Defines the maximum priority to be logged (included). Defaults to "debug".
+
+=item C<-priority> => [ I<parameters> ]
+
+Request that message priority information be part of the log message.
+The given I<parameters> are handed off to the
+creation routine of C<Log::Agent::Tag::Priority> and are documented there.
+
+I usually say something like:
+
+ -priority => [ -display => '[$priority]' ]
+
+which will display the whole priority name at the beginning of the messages,
+e.g. "[warning]" for a warn() or "[error]" for error().
+See L<Log::Agent::Tag::Priority> and L<Log::Agent::Priorities>.
+
+=item C<-tags> => [ I<list of C<Log::Agent::Tag> objects> ]
+
+Specifies user-defined tags to be added to each message. The objects
+given here must inherit from C<Log::Agent::Tag> and conform to its
+interface. See L<Log::Agent::Tag> for details.
+
+At runtime, well after the creation of the logging object, it may be
+desirable to add (or remove) a user tag. Use the C<tags> attribute to
+retrieve the tag list object and interact with it, as explained
+in L<Log::Agent::Tag_List>.
+
+=back
+
+=head2 Logging Interface
+
+Each routine is documented to take a single string, but you may
+also supply a code reference as the first argument, followed by extra
+arguments. That routine will be called, along with the extra arguments,
+to generate the message to be logged. If that sounds crazy, think about
+the CPU time we save by NOT calling the routine. If nothing is returned
+by the routine, nothing is logged.
+
+If more than one argument is given, and the first argument is not a
+code reference, then it is taken as a printf() format, and the remaining
+arguments are used to fill the various "%" placeholders in the format.
+The special "%m" placeholder does not make use of any extra argument and
+is replaced by a stringification of the error message contained in $!,
+aka C<errno>.
+
+There is a logging routine defined for each syslog(3) priority, along
+with aliases for some of them. Here is an exhaustive table, sorted by
+decreasing priority.
+
+ Syslog Alias
+ -------- ---------
+ emerg emergency
+ alert
+ crit critical
+ err error
+ warning warn
+ notice
+ info
+ debug
+
+We shall document only one routine for a given level: for instance,
+we document C<warn> but you could also use the standard C<warning> to
+achieve exactly the same funciton.
+
+=over 4
+
+=item C<emergency($str)>
+
+Log at the "emerg" level, usually just before panicing. Something
+terribly bad has been detected, and the program might crash soon after
+logging this.
+
+=item C<alert($str)>
+
+Log at the "alert" level, to signal a problem requiring immediate
+attention. Usually, some functionality will be missing until the
+condition is fixed.
+
+=item C<critical($str)>
+
+Log at the "crit" level, to signal a severe error that prevents fulfilling
+some activity.
+
+=item C<error($str)>
+
+Log at the "err" level, to signal a regular error.
+
+=item C<warn($str)>
+
+Log at the "warning" level, which is an indication that something unusual
+occurred.
+
+=item C<notice($str)>
+
+Log at the "notice" level, indicating something that is fully handled
+by the applicaiton, but which is not the norm. A significant condition,
+as they say.
+
+=item C<info($str)>
+
+Log at the "info" level, for their amusement.
+
+=item C<debug($str)>
+
+Log at the "debug" level, to further confuse them.
+
+=back
+
+=head2 Closing Channel
+
+=over 4
+
+=item C<close>
+
+This routine closes the channel. Further logging to the logger is
+permitted, but will be simply discarded without notice.
+
+=back
+
+=head2 Attribute Access
+
+The following access routines are defined:
+
+=over 4
+
+=item C<channel>
+
+The defined logging channel. Cannot be changed.
+
+=item C<max_prio> and C<max_prio_str>
+
+Returns the maximum priority recorded, either as a numeric value
+or as a string. For the correspondance between the two, see
+L<Log::Agent::Priorities>.
+
+=item C<min_prio> and C<min_prio_str>
+
+Returns the minimum priority recorded, either as a numeric value
+or as a string. For the correspondance between the two, see
+L<Log::Agent::Priorities>.
+
+=item C<set_caller_info> I<list>
+
+Dynamically change the caller information formatting in the logs.
+The I<list> given supersedes the initial settings done via the C<-caller>
+argument, if any, and is passed to the creation routine of the
+C<Log::Agent::Tag::Caller> class. Note that a plain list must be given,
+not a list ref. An empty list removes caller information from subsequent logs.
+
+Please see L<Log::Agent::Tag::Caller> to get the allowed parameters
+for I<list>.
+
+=item C<set_max_prio($prio)> and C<set_min_prio($prio)>
+
+Used to modify the maximum/minimum priorities. You can use either
+the string value or the numerical equivalent, as documented
+in L<Log::Agent::Priorities>.
+
+=item C<set_priority_info> I<list>
+
+Dynamically change the priority information formatting in the logs.
+The I<list> given supersedes the initial settings done via the C<-priority>
+argument, if any, and is passed to the creation routine of the
+C<Log::Agent::Tag::Priority> class. Note that a plain list must be given,
+not a list ref. An empty list removes priority information from
+subsequent logs.
+
+Please see L<Log::Agent::Tag::Priority> to get the allowed parameters
+for I<list>.
+
+=item C<tags>
+
+Returns a C<Log::Agent::Tag_List> object, which holds all user-defined
+tags that are to be added to each log message.
+
+The initial list of tags is normally supplied by the application at
+creation time, via the C<-tags> argument. See L<Log::Agent::Tag_List>
+for the operations that can be performed on that object.
+
+=back
+
+=head1 AUTHOR
+
+Raphael Manfredi F<E<lt>Raphael_Manfredi at pobox.comE<gt>>
+
+=head1 SEE ALSO
+
+Log::Agent::Channel(3).
+
+=cut
Added: branches/upstream/liblog-agent-logger-perl/current/MANIFEST
URL: http://svn.debian.org/wsvn/branches/upstream/liblog-agent-logger-perl/current/MANIFEST?rev=10227&op=file
==============================================================================
--- branches/upstream/liblog-agent-logger-perl/current/MANIFEST (added)
+++ branches/upstream/liblog-agent-logger-perl/current/MANIFEST Sat Dec 1 12:05:02 2007
@@ -1,0 +1,11 @@
+README The main README file
+MANIFEST This list
+ChangeLog List of changes
+Makefile.PL Generic Makefile template
+Logger.pm Application logging interface
+patchlevel.h Records the current patchlevel
+t/basic.t Basic logging tests
+t/caller.t Test caller information
+t/code.pl Library for tests
+t/priority.t Test -priority settings
+t/tags.t Test log message tags
Added: branches/upstream/liblog-agent-logger-perl/current/Makefile.PL
URL: http://svn.debian.org/wsvn/branches/upstream/liblog-agent-logger-perl/current/Makefile.PL?rev=10227&op=file
==============================================================================
--- branches/upstream/liblog-agent-logger-perl/current/Makefile.PL (added)
+++ branches/upstream/liblog-agent-logger-perl/current/Makefile.PL Sat Dec 1 12:05:02 2007
@@ -1,0 +1,60 @@
+# $Id: Makefile.PL,v 0.1.1.1 2001/04/11 16:14:30 ram Exp $
+#
+# Copyright (c) 2000, 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: Makefile.PL,v $
+# Revision 0.1.1.1 2001/04/11 16:14:30 ram
+# patch1: now depends on Getargs::Long
+# patch1: must use Log::Agent 0.208 or better
+#
+# Revision 0.1 2000/11/06 20:14:13 ram
+# Baseline for first Alpha release.
+#
+# $EndLog$
+#
+
+use ExtUtils::MakeMaker;
+use Log::Agent;
+
+WriteMakefile(
+ 'NAME' => 'Log::Agent::Logger',
+ 'VERSION_FROM' => 'Logger.pm', # finds $VERSION
+ 'PREREQ_PM' => {
+ 'Getargs::Long' => '0.103',
+ 'Log::Agent' => '0.208',
+ },
+ 'PM' => build_pm_hash(),
+ 'LIBS' => [''], # e.g., '-lm'
+ 'DEFINE' => '', # e.g., '-DHAVE_SOMETHING'
+ 'INC' => '', # e.g., '-I/usr/include/other'
+ # 'PREFIX' => '/home/ram/usr/lib/site_perl',
+);
+
+#
+# build_pm_hash
+#
+# Find out all the *.pm files in the MANIFEST, and build a hash ref
+# containing entries like:
+#
+# 'file.pm' => '$(INST_LIBDIR)/file.pm'
+#
+# for each file.
+#
+sub build_pm_hash {
+ local *MANI;
+ open(MANI, "MANIFEST") || logdie "can't open MANIFEST: $!";
+ local $_;
+ my @pm;
+ while (<MANI>) {
+ my ($file, $comment) = split;
+ next unless $file =~ /\.pm$/;
+ push @pm, $file;
+ }
+ my %pm = map { $_ => '$(INST_LIBDIR)/' . $_ } @pm;
+ return \%pm;
+}
+
Added: branches/upstream/liblog-agent-logger-perl/current/README
URL: http://svn.debian.org/wsvn/branches/upstream/liblog-agent-logger-perl/current/README?rev=10227&op=file
==============================================================================
--- branches/upstream/liblog-agent-logger-perl/current/README (added)
+++ branches/upstream/liblog-agent-logger-perl/current/README Sat Dec 1 12:05:02 2007
@@ -1,0 +1,59 @@
+ Log::Agent::Logger 0.1
+ Copyright (c) 2000, Raphael Manfredi
+
+------------------------------------------------------------------------
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the Artistic License, a copy of which can be
+ found with perl.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ Artistic License for more details.
+------------------------------------------------------------------------
+
+ *** This is alpha software -- use at your own risks ***
+
+Name DSLI Description Info
+----------- ---- -------------------------------------------- -----
+Log::Agent ---- A general logging framework RAM
+::Logger adpO Application-level logging interface RAM
+
+
+The Log::Agent::Logger module is an extension of Log::Agent that brings
+an application-level logging API.
+
+It is separated from Log::Agent itself because it has dependencies
+on other CPAN modules that Log::Agent cannot afford to have:
+everyone with a plain stock Perl distribution must be able to simply
+install Log::Agent and start using it.
+
+SYNOPSIS
+ require Log::Agent::Logger;
+
+ my $log = Log::Agent::Logger->make(
+ -channel => $chan,
+ -max_prio => 'info',
+ -min_prio => 'emerg',
+ );
+ $log->error("can't open file %s: $!", $file);
+ $log->warning("can't open file $file: $!");
+
+DESCRIPTION
+ The `Log::Agent::Logger' class defines a generic interface for
+ application logging. It must not be confused with the interface
+ provided by Log::Agent, which is meant to be used by re-usable
+ modules that do not wish to commit on a particular logging method,
+ so that they remain true building blocks.
+
+ By contrast, `Log::Agent::Logger' explicitely requests an object to
+ be used, and that object must commit upon the logging channel to be
+ used, at creation time.
+
+ Optionally, minimum and maximum priority levels may be defined
+ (and changed dynamically) to limit the messages to effectively
+ log, depending on the advertised priority. The standard syslog(3)
+ priorities are used.
+
+-- Raphael Manfredi <Raphael_Manfredi at pobox.com>
+
Added: branches/upstream/liblog-agent-logger-perl/current/patchlevel.h
URL: http://svn.debian.org/wsvn/branches/upstream/liblog-agent-logger-perl/current/patchlevel.h?rev=10227&op=file
==============================================================================
--- branches/upstream/liblog-agent-logger-perl/current/patchlevel.h (added)
+++ branches/upstream/liblog-agent-logger-perl/current/patchlevel.h Sat Dec 1 12:05:02 2007
@@ -1,0 +1,1 @@
+#define PATCHLEVEL 1
Added: branches/upstream/liblog-agent-logger-perl/current/t/basic.t
URL: http://svn.debian.org/wsvn/branches/upstream/liblog-agent-logger-perl/current/t/basic.t?rev=10227&op=file
==============================================================================
--- branches/upstream/liblog-agent-logger-perl/current/t/basic.t (added)
+++ branches/upstream/liblog-agent-logger-perl/current/t/basic.t Sat Dec 1 12:05:02 2007
@@ -1,0 +1,92 @@
+#!./perl
+
+#
+# $Id: basic.t,v 0.1.1.1 2001/04/11 16:15:27 ram Exp $
+#
+# Copyright (c) 2000, 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: basic.t,v $
+# Revision 0.1.1.1 2001/04/11 16:15:27 ram
+# patch1: now tests proper sprintf semantics in log arguments
+#
+# Revision 0.1 2000/11/06 20:14:13 ram
+# Baseline for first Alpha release.
+#
+# $EndLog$
+#
+
+print "1..13\n";
+
+require 't/code.pl';
+sub ok;
+
+sub cleanlog() {
+ unlink <t/logfile*>;
+}
+
+require Log::Agent::Channel::File;
+require Log::Agent::Logger;
+
+cleanlog;
+my $file = "t/logfile";
+my $channel = Log::Agent::Channel::File->make(
+ -prefix => "foo",
+ -stampfmt => "own",
+ -showpid => 1,
+ -filename => $file,
+ -share => 1,
+);
+
+my $log = Log::Agent::Logger->make(
+ -channel => $channel,
+ -max_prio => 'info',
+);
+
+$log->info("this is an %s message", "informational");
+$log->debug("this message (debug) will NOT show");
+$log->emerg("emergency message");
+$log->warn("warning message");
+$log->alert("alert message");
+$log->critical("critical message");
+$log->error("error message");
+$log->notice("notice message");
+
+ok 1, 1 == contains($file, "this is an informational message");
+ok 2, 0 == contains($file, "will NOT show");
+ok 3, 1 == contains($file, "emergency");
+ok 4, 1 == contains($file, "warning");
+ok 5, 1 == contains($file, "alert");
+ok 6, 1 == contains($file, "critical");
+ok 7, 1 == contains($file, "error");
+ok 8, 1 == contains($file, "notice");
+
+#
+# 00/11/06 13:36:33 foo[12138]: warning message
+#
+ok 9, 7 == contains($file,
+ '^\d{2}\/\d{2}\/\d{2} \d{2}:\d{2}:\d{2} foo\[\d+\]: ');
+
+sub genmsg {
+ my ($arg) = @_;
+ return "message #$arg";
+}
+
+$log->notice(\&genmsg, 1);
+$log->notice(\&genmsg, 2);
+$log->notice(sub { join ' ', @_ }, "message", "#3");
+
+ok 10, 1 == contains($file, "message #1");
+ok 11, 1 == contains($file, "message #2");
+ok 12, 1 == contains($file, "message #3");
+
+$log->close;
+$log->notice("will NOT show at all");
+
+ok 13, !contains($file, "will NOT show");
+
+cleanlog;
+
Added: branches/upstream/liblog-agent-logger-perl/current/t/caller.t
URL: http://svn.debian.org/wsvn/branches/upstream/liblog-agent-logger-perl/current/t/caller.t?rev=10227&op=file
==============================================================================
--- branches/upstream/liblog-agent-logger-perl/current/t/caller.t (added)
+++ branches/upstream/liblog-agent-logger-perl/current/t/caller.t Sat Dec 1 12:05:02 2007
@@ -1,0 +1,86 @@
+#!./perl
+
+#
+# $Id: caller.t,v 0.1.1.1 2001/04/11 16:15:54 ram Exp $
+#
+# Copyright (c) 2000, 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: caller.t,v $
+# Revision 0.1.1.1 2001/04/11 16:15:54 ram
+# patch1: created
+#
+# Revision 0.2.1.1 2001/03/13 18:45:44 ram
+# patch2: test the ${line} variable substitution
+#
+# Revision 0.2 2000/11/06 19:30:33 ram
+# Baseline for second Alpha release.
+#
+# $EndLog$
+#
+
+print "1..5\n";
+
+require 't/code.pl';
+sub ok;
+
+sub cleanlog() {
+ unlink <t/logfile*>;
+}
+
+require Log::Agent::Channel::File;
+require Log::Agent::Logger;
+
+cleanlog;
+my $file = "t/logfile";
+my $channel = Log::Agent::Channel::File->make(
+ -prefix => "foo",
+ -stampfmt => "own",
+ -showpid => 1,
+ -filename => $file,
+ -share => 1,
+);
+
+my $log = Log::Agent::Logger->make(
+ -channel => $channel,
+ -max_prio => 'info',
+ -caller => [ -format => "<%s,%.4d>", -info => "sub line", -postfix => 1 ],
+);
+
+my $show_error = __LINE__ + 2;
+sub show_error {
+ $_[0]->error("error string");
+}
+
+sub notice_string { "notice string" }
+
+my $show_notice = __LINE__ + 2;
+sub show_notice {
+ $_[0]->notice(\¬ice_string);
+}
+
+show_error($log);
+show_notice($log);
+
+$log->set_caller_info(-display => "<nothing>");
+$log->error("error2 string");
+
+$log->set_caller_info();
+$log->error("error3 string");
+
+$log->close;
+
+my $error_str = sprintf("%.4d", $show_error);
+my $notice_str = sprintf("%.4d", $show_notice);
+
+ok 1, contains($file, "error string <main::show_error,$error_str>");
+ok 2, contains($file, "notice string <main::show_notice,$notice_str>");
+ok 3, contains($file, '<nothing> error2 string$');
+ok 4, contains($file, 'error3 string$');
+ok 5, !contains($file, '> error3 string$');
+
+cleanlog;
+
Added: branches/upstream/liblog-agent-logger-perl/current/t/code.pl
URL: http://svn.debian.org/wsvn/branches/upstream/liblog-agent-logger-perl/current/t/code.pl?rev=10227&op=file
==============================================================================
--- branches/upstream/liblog-agent-logger-perl/current/t/code.pl (added)
+++ branches/upstream/liblog-agent-logger-perl/current/t/code.pl Sat Dec 1 12:05:02 2007
@@ -1,0 +1,37 @@
+#
+# $Id: code.pl,v 0.1 2000/11/06 20:14:13 ram Exp $
+#
+# Copyright (c) 2000, 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: code.pl,v $
+# Revision 0.1 2000/11/06 20:14:13 ram
+# Baseline for first Alpha release.
+#
+# $EndLog$
+#
+
+sub ok {
+ my ($num, $ok) = @_;
+ print "not " unless $ok;
+ print "ok $num\n";
+}
+
+sub contains {
+ my ($file, $pattern) = @_;
+ local *FILE;
+ local $_;
+ open(FILE, $file) || die "can't open $file: $!\n";
+ my $found = 0;
+ while (<FILE>) {
+ $found++ if /$pattern/;
+ }
+ close FILE;
+ return $found;
+}
+
+1;
+
Added: branches/upstream/liblog-agent-logger-perl/current/t/priority.t
URL: http://svn.debian.org/wsvn/branches/upstream/liblog-agent-logger-perl/current/t/priority.t?rev=10227&op=file
==============================================================================
--- branches/upstream/liblog-agent-logger-perl/current/t/priority.t (added)
+++ branches/upstream/liblog-agent-logger-perl/current/t/priority.t Sat Dec 1 12:05:02 2007
@@ -1,0 +1,74 @@
+#!./perl
+
+#
+# $Id: priority.t,v 0.1.1.1 2001/04/11 16:15:58 ram Exp $
+#
+# Copyright (c) 2000, 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: priority.t,v $
+# Revision 0.1.1.1 2001/04/11 16:15:58 ram
+# patch1: created
+#
+# Revision 0.2.1.1 2001/03/13 18:48:06 ram
+# patch2: fixed bug for *BSD systems
+# patch2: created
+#
+# Revision 0.2 2000/11/06 19:30:33 ram
+# Baseline for second Alpha release.
+#
+# $EndLog$
+#
+
+print "1..6\n";
+
+require 't/code.pl';
+sub ok;
+
+sub cleanlog() {
+ unlink <t/logfile*>;
+}
+
+require Log::Agent::Channel::File;
+require Log::Agent::Logger;
+
+cleanlog;
+my $file = "t/logfile";
+my $channel = Log::Agent::Channel::File->make(
+ -prefix => "foo",
+ -stampfmt => "own",
+ -showpid => 1,
+ -filename => $file,
+ -share => 1,
+);
+
+my $log = Log::Agent::Logger->make(
+ -channel => $channel,
+ -max_prio => 'info',
+ -priority => [ -display => '<$priority/$level>', -prefix => 1 ],
+);
+
+$log->error("error string");
+$log->notice("notice string");
+$log->info("info string");
+
+$log->set_priority_info(-display => '<$priority>');
+$log->info("info2 string");
+
+$log->set_priority_info();
+$log->info("info3 string");
+
+$log->close;
+
+ok 1, contains($file, "<error/3> error string");
+ok 2, contains($file, "<notice/6> notice string");
+ok 3, contains($file, "<info/8> info string");
+ok 4, contains($file, "<info> info2 string");
+ok 5, contains($file, "info3 string");
+ok 6, !contains($file, "> info3 string");
+
+cleanlog;
+
Added: branches/upstream/liblog-agent-logger-perl/current/t/tags.t
URL: http://svn.debian.org/wsvn/branches/upstream/liblog-agent-logger-perl/current/t/tags.t?rev=10227&op=file
==============================================================================
--- branches/upstream/liblog-agent-logger-perl/current/t/tags.t (added)
+++ branches/upstream/liblog-agent-logger-perl/current/t/tags.t Sat Dec 1 12:05:02 2007
@@ -1,0 +1,65 @@
+#!./perl
+
+#
+# $Id: tags.t,v 0.1.1.1 2001/04/11 16:16:02 ram Exp $
+#
+# Copyright (c) 2000, 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: tags.t,v $
+# Revision 0.1.1.1 2001/04/11 16:16:02 ram
+# patch1: created
+#
+# Revision 0.2.1.1 2001/03/13 18:49:29 ram
+# patch2: created
+#
+# Revision 0.2 2000/11/06 19:30:33 ram
+# Baseline for second Alpha release.
+#
+# $EndLog$
+#
+
+print "1..2\n";
+
+require 't/code.pl';
+sub ok;
+
+sub cleanlog() {
+ unlink <t/logfile*>;
+}
+
+require Log::Agent::Channel::File;
+require Log::Agent::Logger;
+require Log::Agent::Tag::String;
+
+cleanlog;
+my $file = "t/logfile";
+my $channel = Log::Agent::Channel::File->make(
+ -prefix => "foo",
+ -stampfmt => "own",
+ -showpid => 1,
+ -filename => $file,
+ -share => 1,
+);
+
+my $t1 = Log::Agent::Tag::String->make(-value => "<tag #1>");
+my $t2 = Log::Agent::Tag::String->make(-value => "<tag #2>", -postfix => 1);
+
+my $log = Log::Agent::Logger->make(
+ -channel => $channel,
+ -max_prio => 'info',
+ -tags => [$t1],
+);
+
+$log->err("error string");
+$log->tags->append($t2);
+$log->warn("warn string");
+
+ok 1, contains($file, '<tag #1> error string$');
+ok 2, contains($file, '<tag #1> warn string <tag #2>$');
+
+cleanlog;
+
More information about the Pkg-perl-cvs-commits
mailing list