App-Framework
view release on metacpan or search on metacpan
lib/App/Framework/Feature/Logging.pm view on Meta::CPAN
=cut
my %FIELDS = (
'logfile' => undef,
'mode' => 'truncate',
'to_stdout' => 0,
## private
'_started' => 0,
) ;
=head2 ADDITIONAL COMMAND LINE OPTIONS
This feature adds the following additional command line options to any application:
=over 4
=item B<-log> - Specify a log file
If a logfile is specified at the command line, then the file is created and all logging messages get written to that file.
Otherwise, log messages are ignored.
=back
=cut
my @OPTIONS = (
['log=s', 'Log file', 'Specify a log file', ],
) ;
#============================================================================================
=head2 CONSTRUCTOR
=over 4
=cut
#============================================================================================
=item B< new([%args]) >
Create a new Logging.
The %args are specified as they would be in the B<set> method (see L</Fields>).
=cut
sub new
{
my ($obj, %args) = @_ ;
my $class = ref($obj) || $obj ;
# Create object
my $this = $class->SUPER::new(%args,
'feature_options' => \@OPTIONS,
'registered' => [qw/application_entry/],
) ;
#$this->debug(2);
return($this) ;
}
#============================================================================================
=back
=head2 CLASS METHODS
=over 4
=cut
#============================================================================================
#-----------------------------------------------------------------------------
=item B< init_class([%args]) >
Initialises the Logging object class variables.
=cut
sub init_class
{
my $class = shift ;
my (%args) = @_ ;
# Add extra fields
$class->add_fields(\%FIELDS, \%args) ;
# init class
$class->SUPER::init_class(%args) ;
}
#============================================================================================
=back
=head2 OBJECT METHODS
=over 4
=cut
#============================================================================================
#----------------------------------------------------------------------------
=item B<application_entry()>
Called by the application framework at the start of the application.
This method checks for the user specifying any of the options described above (see L</ADDITIONAL COMMAND LINE OPTIONS>) and handles
them if so.
=cut
sub application_entry
{
my $this = shift ;
$this->_dbg_prt(["application_entry()\n"]) ;
## Handle special options
my $app = $this->app ;
my %opts = $app->options() ;
$this->_dbg_prt(["logging options=",\%opts]) ;
if ($opts{'log'})
{
$this->logfile($opts{'log'}) ;
}
}
#----------------------------------------------------------------------------
=item B<logging($arg1, [$arg2, ....])>
Log the argument(s) to the log file iff a log file has been specified.
The list of arguments may be: SCALAR, ARRAY reference, HASH reference, SCALAR reference. SCALAR and SCALAR ref are printed
as-is without any extra newlines. ARRAY ref is printed out one entry per line with a newline added. The HASH ref is printed out
in the format produced by L<App::Framework::Base::Object::DumpObj>.
=cut
( run in 0.950 second using v1.01-cache-2.11-cpan-0bb4e1dffa6 )