The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

Name

Class::Usul::Log - Create methods for each logging level that encode their output

Synopsis

   use Class::Usul::Log;
   use File::DataClass::IO;

   my $file = io [ 't', 'test.log' ];
   my $log  = Class::Usul::Log->new( encoding => 'UTF-8', logfile => $file );
   my $text = 'Your error message goes here';

   # Can now call the following. The text will be encoded UTF-8
   $log->debug( $text ); # Does not log as debug was not true in the constructor
   $log->info ( $text );
   $log->warn ( $text );
   $log->error( $text );
   $log->alert( $text );
   $log->fatal( $text );

Description

Creates methods for each logging level that encode their output. The logging levels are defined by the log levels constant

Configuration and Environment

Defines the following attributes

debug

Debug flag defaults to false. If set to true calls to log at the debug level will succeed rather than being ignored

encoding

Optional output encoding. If present output to the logfile is encoded

log

Optional log object. Will instantiate an instance of Log::Handler if this is not provided

log_attributes

Attributes used to create the log object

log_class

The classname of the log object. This is loaded on demand

logfile

Path to the logfile

Subroutines/Methods

BUILDARGS

Monkey with the constructors signature

filehandle

Return the loggers file handle. This was added for IO::Async, so that we can tell it not to close the log file handle when it forks a child process

get_log_attributes

Returns the hash reference passed to the constructor of the log class. Returns undef to indicate no logging, an instance of Class::Null is used instead

log

   $self->log( { level => $level, message => $message } );

Logs the message at the given level

Diagnostics

None

Dependencies

Class::Null
Moo
Encode
File::DataClass
Log::Handler

Incompatibilities

There are no known incompatibilities in this module

Bugs and Limitations

There are no known bugs in this module. Please report problems to the address below. Patches are welcome

Acknowledgements

Larry Wall - For the Perl programming language

Author

Peter Flanigan, <pjfl@cpan.org>

License and Copyright

Copyright (c) 2015 Peter Flanigan. All rights reserved

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic

This program is distributed in the hope that it will be useful, but WITHOUT WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE