Sélectionner une révision Git
-
Alexandre Morignot a rédigéAlexandre Morignot a rédigé
Logging.pm 10,85 Kio
package PlayBot::utils::Logging;
# ==============[ Classe pour gérer les logs correctement ]============== #
# Date : 29/10/2010 #
# Auteur : TC #
# ======================================================================= #
use strict;
use warnings;
use utf8;
use Fcntl ':mode';
# ###
# new
# Instancie la classe - un constructeur en somme
# ###
sub new {
my $class = shift;
my $self = {
_file => shift,
_colored => 0,
_pending => 0,
_utf8 => 0,
_right_align => shift,
};
bless $self, $class;
# On active la couleur que si on est sur un terminal
# C'est moche après pour les fichiers ou un less
if ( $self->file eq "STDOUT" ) {
$self->{"_colored"} = 1 if ( ( stat(STDOUT) )[2] & S_IFCHR );
}
elsif ( $self->file eq "STDERR" ) {
$self->{"_colored"} = 1 if ( ( stat(STDERR) )[2] & S_IFCHR );
}
else {
$self->{"_colored"} = 1 if ( ( stat( $self->file ) )[2] & S_IFCHR );
}
unless ( defined $self->{"_right_align"} ) {
$self->{"_right_align"} = 0;
}
return $self;
} # Fin new
# ###
# file
# Renvoie/maj $self->{'_file'}
# ###
sub file {
my $self = shift;
$self->{"_file"} = $_[0] if ( defined( $_[0] ) );
return $self->{"_file"};
} # Fin file
# ###
# colored
# Renvoie/maj $self->{'_colored'}
# ###
sub colored {
my $self = shift;
$self->{"_colored"} = $_[0] if ( defined( $_[0] ) );
return $self->{"_colored"};
} # Fin colored
# ###
# pending