<commit_before>package Log::Dispatch;

require 5.005;

use strict;
use vars qw[ $VERSION %LEVELS ];

use base qw( Log::Dispatch::Base );
use fields qw( outputs callbacks );

use Carp ();

$VERSION = '2.00';

1;

BEGIN
{
    no strict 'refs';
    foreach my $l ( qw( debug info notice warning err error crit critical alert emerg emergency ) )
    {
	*{$l} = sub { my $self = shift;
		      $self->log( level => $l, message => "@_" ); };
	$LEVELS{$l} = 1;
    }
}

sub new
{
    my $proto = shift;
    my $class = ref $proto || $proto;
    my %params = @_;

    my $self = bless {}, $class;

    my @cb = $self->_get_callbacks(%params);
    $self->{callbacks} = \@cb if @cb;

    return $self;
}

sub add
{
    my $self = shift;
    my $object = shift;

    # Once 5.6 is more established start using the warnings module.
    if (exists $self->{outputs}{$object->name} && $^W)
    {
	Carp::carp("Log::Dispatch::* object ", $object->name, " already exists.");
    }

    $self->{outputs}{$object->name} = $object;
}

sub remove
{
    my $self = shift;
    my $name = shift;

    return delete $self->{outputs}{$name};
}

sub log
{
    my $self = shift;
    my %params = @_;

    $params{message} = $self->_apply_callbacks(%params)
	if $self->{callbacks};

    foreach (keys %{ $self->{outputs} })
    {
	$params{name} = $_;
	$self->_log_to(%params);
    }
}

sub log_to
{
    my $self = shift;
    my %params = @_;

    $params{message} = $self->_apply_callbacks(%params)
	if $self->{callbacks};

    $self->_log_to(%params);
}

sub _log_to
{
    my $self = shift;
    my %params = @_;
    my $name = delete $params{name};

    if (exists $self->{outputs}{$name})
    {
	$self->{outputs}{$name}->log(@_);
    }
    else
    {
	Carp::carp("Log::Dispatch::* object named '$name' not in dispatcher\n");
    }
}

sub level_is_valid<commit_msg>remove weird delete<commit_after>package Log::Dispatch;

require 5.005;

use strict;
use vars qw[ $VERSION %LEVELS ];

use base qw( Log::Dispatch::Base );
use fields qw( outputs callbacks );

use Carp ();

$VERSION = '2.00';

1;

BEGIN
{
    no strict 'refs';
    foreach my $l ( qw( debug info notice warning err error crit critical alert emerg emergency ) )
    {
	*{$l} = sub { my $self = shift;
		      $self->log( level => $l, message => "@_" ); };
	$LEVELS{$l} = 1;
    }
}

sub new
{
    my $proto = shift;
    my $class = ref $proto || $proto;
    my %params = @_;

    my $self = bless {}, $class;

    my @cb = $self->_get_callbacks(%params);
    $self->{callbacks} = \@cb if @cb;

    return $self;
}

sub add
{
    my $self = shift;
    my $object = shift;

    # Once 5.6 is more established start using the warnings module.
    if (exists $self->{outputs}{$object->name} && $^W)
    {
	Carp::carp("Log::Dispatch::* object ", $object->name, " already exists.");
    }

    $self->{outputs}{$object->name} = $object;
}

sub remove
{
    my $self = shift;
    my $name = shift;

    return delete $self->{outputs}{$name};
}

sub log
{
    my $self = shift;
    my %params = @_;

    $params{message} = $self->_apply_callbacks(%params)
	if $self->{callbacks};

    foreach (keys %{ $self->{outputs} })
    {
	$params{name} = $_;
	$self->_log_to(%params);
    }
}

sub log_to
{
    my $self = shift;
    my %params = @_;

    $params{message} = $self->_apply_callbacks(%params)
	if $self->{callbacks};

    $self->_log_to(%params);
}

sub _log_to
{
    my $self = shift;
    my %params = @_;
    my $name = $params{name};

    if (exists $self->{outputs}{$name})
    {
	$self->{outputs}{$name}->log(@_);
    }
    else
    {
	Carp::carp("Log::Dispatch::* object named '$name' not in dispatcher\n");
    }
}

sub level_is_valid
{'fraction_non_alphanumeric': 0.1863252519749387, 'fraction_numerical': 0.0059929174611822395, 'mean_word_length': 2.857142857142857, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3768129', 'n_tokens_mistral': 1394, 'n_tokens_neox': 1341, 'n_words': 346}