Archive Ensembl HomeArchive Ensembl Home
RunnableLogger.pm
Go to the documentation of this file.
00001 #
00002 # You may distribute this module under the same terms as perl itself
00003 #
00004 
00005 =pod
00006 
00007 =head1 NAME
00008 
00009 Bio::EnsEMBL::Compara::Production::Projection::RunnableDB::RunnableLogger
00010 
00011 =head1 DESCRIPTION
00012 
00013 This class is a mirror of the calls we can expect to use on a L<Log::Log4perl>
00014 logger class. This allows runnables to use Log4perl should it exist on 
00015 a user's @INC otherwise it defaults to the more normal logging to stdout. It
00016 does not provide catagory support just the basic logging interface.
00017 
00018 =head1 AUTHOR
00019 
00020 Andy Yates (ayatesatebiacuk)
00021 
00022 =head1 CONTACT
00023 
00024 This modules is part of the EnsEMBL project (http://www.ensembl.org)
00025 
00026 Questions can be posted to the dev mailing list: dev@ensembl.org
00027 
00028 =cut
00029 
00030 package Bio::EnsEMBL::Compara::Production::Projection::RunnableDB::RunnableLogger;
00031 
00032 use strict;
00033 use warnings;
00034 use Bio::EnsEMBL::Utils::Argument qw(rearrange);
00035 
00036 =head2 new()
00037 
00038   Arg[DEBUG]  : Indicates if debug mode is on.
00039   Arg[STDERR] : Indicates we need to write out to STDERR
00040   Arg[TRACE]  : Indicates if trace mode is on (defaults to 0)
00041   Description : Constructor for the logger
00042 
00043 =cut
00044 
00045 sub new {
00046   my ( $class, @args ) = @_;
00047   my $self = bless( {}, ref($class) || $class );
00048   my ( $debug, $stderr, $trace ) = rearrange( [qw(debug stderr trace)], @args );
00049   $self->_debug($debug);
00050   $self->_stderr($stderr);
00051   $self->_trace($trace);
00052   return $self;
00053 }
00054 
00055 sub _debug {
00056   my ($self, $_debug) = @_;
00057   $self->{_debug} = $_debug if defined $_debug;
00058   return $self->{_debug};
00059 }
00060 
00061 sub _stderr {
00062   my ($self, $_stderr) = @_;
00063   $self->{_stderr} = $_stderr if defined $_stderr;
00064   return $self->{_stderr};
00065 }
00066 
00067 sub _trace {
00068   my ($self, $_trace) = @_;
00069   $self->{_trace} = $_trace if defined $_trace;
00070   return $self->{_trace};
00071 }
00072 
00073 =head2 fatal()
00074 
00075 Issues an Ensembl warning with the message
00076 
00077 =cut
00078 
00079 sub fatal {
00080   my ($self, $message) = @_;
00081   $self->_print("FATAL: $message");
00082   return; 
00083 }
00084 
00085 =head2 is_fatal()
00086 
00087 Always returns true
00088 
00089 =cut
00090 
00091 sub is_fatal {
00092   return 1;
00093 }
00094 
00095 =head2 error()
00096 
00097 Issues an Ensembl warning with the message
00098 
00099 =cut
00100 
00101 sub error {
00102   my ($self, $message) = @_;
00103   $self->_print("ERROR: $message");
00104   return;
00105 }
00106 
00107 =head2 is_error()
00108 
00109 Always returns true
00110 
00111 =cut
00112 
00113 sub is_error {
00114   return 1;
00115 }
00116 
00117 =head2 warning()
00118 
00119 Issues an Ensembl warning with the message
00120 
00121 =cut
00122 
00123 sub warning {
00124   my ($self, $message) = @_;
00125   $self->_print("WARN: $message");
00126   return;
00127 }
00128 
00129 =head2 is_warning()
00130 
00131 Always returns true
00132 
00133 =cut
00134 
00135 sub is_warning {
00136   return 1;
00137 }
00138 
00139 =head2 info()
00140 
00141 Prints the message to STDOUT
00142 
00143 =cut
00144 
00145 sub info {
00146   my ($self, $message) = @_;
00147   $self->_print("INFO: $message");
00148   return;
00149 }
00150 
00151 =head2 is_info()
00152 
00153 Always returns true
00154 
00155 =cut
00156 
00157 sub is_info {
00158   my ($self) = @_;
00159   return 1;
00160 }
00161 
00162 =head2 debug()
00163 
00164 Prints to STDOUT if the object was contstructed with the debug flag on
00165 
00166 =cut
00167 
00168 sub debug {
00169   my ($self, $message) = @_;
00170   return unless $self->is_debug();
00171   $self->_print("DEBUG: $message");
00172   return;
00173 }
00174 
00175 =head2 is_debug()
00176 
00177 Returns true if debug was given as true during construction
00178 
00179 =cut
00180 
00181 sub is_debug {
00182   my ($self) = @_;
00183   return $self->_debug();
00184 }
00185 
00186 =head2 trace()
00187 
00188 Prints the message to STDOUT if is_trace() responded true
00189 
00190 =cut
00191 
00192 sub trace {
00193   my ($self, $message) = @_;
00194   return unless $self->is_trace();
00195   $self->_print("TRACE: $message");
00196   return;
00197 }
00198 
00199 =head2 is_trace()
00200 
00201 Returns true if debug was given as true during construction
00202 
00203 =cut
00204 
00205 sub is_trace {
00206   my ($self) = @_;
00207   return $self->_trace();
00208 }
00209 
00210 sub _print {
00211   my ($self, $msg) = @_;
00212   if($self->_stderr()) {
00213     print STDERR $msg, "\n";
00214   }
00215   else {
00216     print STDOUT $msg, "\n";
00217   }
00218   return;
00219 }
00220 
00221 1;