<commit_before>package PEF::Log::Appender;
use Carp;
use Clone 'clone';
use strict;
use warnings;

# typical params are:
#    out:    -- output stream or file
#    format: -- name of format
#    filter: -- user supplied message transformation filter

sub new {
	my ($class, %params) = @_;
	my $self = {%params};
	if (exists ($params{filter}) && $params{filter}) {
		eval "use $params{filter}";
		croak $@ if $@;
		$self->{filter} = "$params{filter}"->new(\%params);
	}
	if (exists ($params{format}) && $params{format}) {
		no warnings 'once';
		if (not exists $PEF::Log::Config::config{formats}{$params{format}}) {
			croak "unknown format $params{format}";
		}
		$self->{formatter} = $PEF::Log::Config::config{formats}{$params{format}};
	}
	bless $self, $class;
}

sub append {
	my ($self, $level, $sublevel, $msg) = @_;
	if ($self->{filter}) {
		$msg = clone $msg;
		$self->{filter}->transform($level, $sublevel, $msg);
	}
	if ($self->{formatter}) {
		return $self->{formatter}->($level, $sublevel, $msg);
	}
	$msg;
}

1;<commit_msg>filter transformation api changes<commit_after>package PEF::Log::Appender;
use Carp;
use Clone 'clone';
use strict;
use warnings;

# typical params are:
#    out:    -- output stream or file
#    format: -- name of format
#    filter: -- user supplied message transformation filter

sub new {
	my ($class, %params) = @_;
	my $self = {%params};
	if (exists ($params{filter}) && $params{filter}) {
		eval "use $params{filter}";
		croak $@ if $@;
		$self->{filter} = "$params{filter}"->new(\%params);
	}
	if (exists ($params{format}) && $params{format}) {
		no warnings 'once';
		if (not exists $PEF::Log::Config::config{formats}{$params{format}}) {
			croak "unknown format $params{format}";
		}
		$self->{formatter} = $PEF::Log::Config::config{formats}{$params{format}};
	}
	bless $self, $class;
}

sub append {
	my ($self, $level, $sublevel, $msg) = @_;
	if ($self->{filter}) {
		$msg = $self->{filter}->transform($level, $sublevel, clone $msg);
	}
	if ($self->{formatter}) {
		return $self->{formatter}->($level, $sublevel, $msg);
	}
	$msg;
}

1;
{'fraction_non_alphanumeric': 0.21229586935638808, 'fraction_numerical': 0.0009606147934678194, 'mean_word_length': 4.438642297650131, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, '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': '5967295', 'n_tokens_mistral': 790, 'n_tokens_neox': 751, 'n_words': 183}