<commit_before>package Log::Dispatch::ApacheLog;

use strict;

use Log::Dispatch::Output;

use base qw( Log::Dispatch::Output );
use fields qw( apache_log );

use Apache::Log;

use vars qw[ $VERSION ];

$VERSION = sprintf "%d.%02d", q$Revision: 1.5 $ =~ /: (\d+)\.(\d+)/;

1;

sub new
{
    my $proto = shift;
    my $class = ref $proto || $proto;

    my %params = @_;

    my $self = bless {}, $class;

    $self->_basic_init(%params);
    $self->{apache_log} = UNIVERSAL::isa( $params{apache}, 'Apache::Server' ) ? $params{apache}->log : $params{apache}->log;

    return $self;
}

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

    my $method;

    if ($params{level} eq 'emergency')
    {
	$method = 'emerg';
    }
    elsif ( $params{level} eq 'critical' )
    {
	$method = 'crit';
    }
    elsif( $params{level} eq 'err' )
    {
	$method = 'error';
    }
    elsif( $params{level} eq 'warning' )
    {
	$method = 'warn';
    }
    else
    {
	$method = $params{level};
    }

    $self->{apache_log}->$method( $params{message} );
}

__END__

=head1 NAME

Log::Dispatch::ApacheLog - Object for logging to Apache::Log objects

=head1 SYNOPSIS

  use Log::Dispatch::ApacheLog;

  my $handle = Log::Dispatch::ApacheLog->new( name      => 'apache log',
                                              min_level => 'emerg',
                                              apache    => $r );

  $handle->log( level => 'emerg', message => 'Kaboom' );

=head1 DESCRIPTION

This module allows you to pass messages Apache's log object,
represented by the Apache::Log class.

=head1 METHODS

=over 4

=item * new(%PARAMS)

This method takes a hash of parameters.  The following options are
valid:

=item -- name ($)

The name of the object (not the filename!).  Required.

=item -- min_level ($)<commit_msg>use P::V params => P<commit_after>package Log::Dispatch::ApacheLog;

use strict;

use Log::Dispatch::Output;

use base qw( Log::Dispatch::Output );

use Params::Validate qw(validate);
Params::Validate::validation_options( allow_extra => 1 );

use Apache::Log;

use vars qw[ $VERSION ];

$VERSION = sprintf "%d.%02d", q$Revision: 1.6 $ =~ /: (\d+)\.(\d+)/;

1;

sub new
{
    my $proto = shift;
    my $class = ref $proto || $proto;

    my %p = validate( @_, { apache => { can => 'log' } } );

    my $self = bless {}, $class;

    $self->_basic_init(%p);
    $self->{apache_log} = $p{apache}->log;

    return $self;
}

sub log_message
{
    my $self = shift;
    my %p = @_;

    my $method;

    if ($p{level} eq 'emergency')
    {
	$method = 'emerg';
    }
    elsif ( $p{level} eq 'critical' )
    {
	$method = 'crit';
    }
    elsif( $p{level} eq 'err' )
    {
	$method = 'error';
    }
    elsif( $p{level} eq 'warning' )
    {
	$method = 'warn';
    }
    else
    {
	$method = $p{level};
    }

    $self->{apache_log}->$method( $p{message} );
}

__END__

=head1 NAME

Log::Dispatch::ApacheLog - Object for logging to Apache::Log objects

=head1 SYNOPSIS

  use Log::Dispatch::ApacheLog;

  my $handle = Log::Dispatch::ApacheLog->new( name      => 'apache log',
                                              min_level => 'emerg',
                                              apache    => $r );

  $handle->log( level => 'emerg', message => 'Kaboom' );

=head1 DESCRIPTION

This module allows you to pass messages Apache's log object,
represented by the Apache::Log class.

=head1 METHODS

=over 4

=item * new(%p)

This method takes a hash of parameters.  The following options are
valid:

=item -- name ($)

The name of the object (not the filename!).  Required.

=item -- min_level ($)
{'fraction_non_alphanumeric': 0.1669435215946844, 'fraction_numerical': 0.005813953488372093, 'mean_word_length': 2.5772277227722773, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 32, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1836487', 'n_tokens_mistral': 1304, 'n_tokens_neox': 1241, 'n_words': 339}