Skip to content
Extraits de code Groupes Projets
Sélectionner une révision Git
  • 1f8f2d381e3a9c7b47b330186364b45c9e6ca4eb
  • master par défaut
  • cinch
  • ruby
  • gh-pages
  • v1.0.0
6 résultats

Logging.pm

Blame
  • 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