Log::Fine::Levels - Define variable logging levels


Log-Fine documentation Contained in the Log-Fine distribution.

Index


Code Index:

NAME

Top

Log::Fine::Levels - Define variable logging levels

SYNOPSIS

Top

Provides logging translations

    use Log::Fine::Levels;

    # instantiate the levels object using the default translations
    my $levels = Log::Fine::Levels->new();

    # instantiate the levels object using customized translations
    my $levels = Log::Fine::Levels->new("Java");

    # Supported methods
    my @l = $levels->logLevels();   # grab list of levels
    my @m = $levels->logMasks();    # grab list of masks

    # translation methods
    my $val     = $levels->levelToValue("INFO");
    my $bitmask = $levels->maskToValue("LOGMASK_INFO");
    my $lvl     = $levels->valueToLevel(3);

DESCRIPTION

Top

Log::Fine::Levels is used by the Log::Fine framework to translate customizable log levels (such as INFO, DEBUG, WARNING, etc) to and from an associated value as well as convenience methods for interacting with log levels (such as grabbing a list of levels).

In addition, the Log::Fine framework supports the notion of a mask, which is used for customizing output. See Log::Fine::Handle for more details as to how masks are used.

Customization

Log::Fine::Levels only provides methods for interacting with log levels and associated log masks. In order to define levels and masks, it must be overridden. Note that, by default, the Log::Fine::Levels::Syslog class is used to define log levels.

Independence

Finally, Log::Fine::Levels is written to be independant of the Log::Fine framework and, as such, does not inherit any methods from Log::Fine. This allows developers to use Log::Fine::Levels by itself for defining customizable level packages for use in their own programs.

METHODS

Top

The following methods are provided:

new

Creates a new Log::Fine::Levels object

Parameters

* levelmap

The name of the level map to use (e.g., Syslog, Java, etc)

Returns

an Log::Fine::Levels object

bitmaskAll

Getter for a bitmask representing ALL possible values

Returns

Bitmask representing all possible mask values

levelToValue

Level name to numeric value

Parameters

* level name

The name of the level

Returns

The numeric value representing the given level name. Undef if name is not defined

logLevels

Getter for all log levels

Returns

An array representing all level names, sorted by ascending numeric value

logMasks

Getter for all log masks

Returns

An array representing all mask names, sorted by ascending numeric value

maskToValue

Mask name to numeric value

Parameters

* mask name

The name of the mask

Returns

The numeric value representing the given mask name. Undef if name is not defined

valueToLevel

Level value to level name

Parameters

* numeric value

The numeric value representing a level

Returns

The level name associated with the given numeric value. Undef if the value is not defined

BUGS

Top

Please report any bugs or feature requests to bug-log-fine at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Log-Fine. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

Top

You can find documentation for this module with the perldoc command.

    perldoc Log::Fine::Levels

You can also look for information at:

* AnnoCPAN: Annotated CPAN documentation

http://annocpan.org/dist/Log-Fine

* CPAN Ratings

http://cpanratings.perl.org/d/Log-Fine

* RT: CPAN's request tracker

http://rt.cpan.org/NoAuth/Bugs.html?Dist=Log-Fine

* Search CPAN

http://search.cpan.org/dist/Log-Fine

REVISION INFORMATION

Top

  $Id: 18a375bed498e68eaff5ed39bae1432cec95bc9b $

AUTHOR

Top

Christopher M. Fuhrman, <cfuhrman at panix.com>

SEE ALSO

Top

perl, syslog, Log::Fine, Sys::Syslog

COPYRIGHT & LICENSE

Top


Log-Fine documentation Contained in the Log-Fine distribution.
use strict;
use warnings;

package Log::Fine::Levels;

use Carp;
use Log::Fine;

our $VERSION = $Log::Fine::VERSION;

# Constants
# --------------------------------------------------------------------

use constant DEFAULT_LEVELMAP => "Syslog";

# --------------------------------------------------------------------

sub new
{

        my $class = shift;
        my $lvlmap = shift || DEFAULT_LEVELMAP;

        # construct the subclass
        my $levelClass = join("::", $class, $lvlmap);

        # validate levelclass
        eval "require $levelClass";

        # Do we have the class defined?
        confess "Error : Level Class $levelClass does not exist : $@"
            if $@;

        # return the new subclass
        return $levelClass->new();

}          # new()

sub bitmaskAll
{

        my $self = shift;

        # variable for storing the total bitmask
        my $mask = 0;

        # bitor all the mask values together
        $mask |= $self->MASK_MAP->{$_} foreach (keys %{ $self->MASK_MAP });

        return $mask;

}          # bitmaskAll()

sub levelToValue
{

        my $self = shift;
        my $lvl  = shift;

        return $self->LVLTOVAL_MAP->{$lvl};

}          # levelToValue()

sub logLevels
{

        my $self = shift;
        my @lvls;

        # construct array sorted by level value (ascending) and return
        push @lvls, $self->VALTOLVL_MAP->{$_}
            foreach (sort { $a <=> $b } (keys %{ $self->VALTOLVL_MAP }));
        return @lvls;

}          # logLevels()

sub logMasks
{

        my $self = shift;
        my $vtom = {};
        my @masks;

        # build hash of mask values to mask names
        $vtom->{ $self->MASK_MAP->{$_} } = $_
            foreach (keys %{ $self->MASK_MAP });

        # construct array sorted by mask value (ascending) and return
        push @masks, $vtom->{$_} foreach (sort { $a <=> $b } (keys %{$vtom}));
        return @masks;

}          # logMasks()

sub maskToValue
{

        my $self = shift;
        my $mask = shift;

        return $self->MASK_MAP->{$mask};

};          # maskToValue()

sub valueToLevel
{

        my $self = shift;
        my $val  = shift;

        return $self->VALTOLVL_MAP->{$val}

}          # valueToLevel()

1;          # End of Log::Fine::Levels