summaryrefslogtreecommitdiffstats
path: root/Log/Log4perl
diff options
context:
space:
mode:
authorPerl Tidy <perltidy@bugzilla.org>2018-12-05 21:38:52 +0100
committerDylan William Hardison <dylan@hardison.net>2018-12-05 23:49:08 +0100
commit8ec8da0491ad89604700b3e29a227966f6d84ba1 (patch)
tree9d270f173330ca19700e0ba9f2ee931300646de1 /Log/Log4perl
parenta7bb5a65b71644d9efce5fed783ed545b9336548 (diff)
downloadbugzilla-8ec8da0491ad89604700b3e29a227966f6d84ba1.tar.gz
bugzilla-8ec8da0491ad89604700b3e29a227966f6d84ba1.tar.xz
no bug - reformat all the code using the new perltidy rules
Diffstat (limited to 'Log/Log4perl')
-rw-r--r--Log/Log4perl/Layout/Mozilla.pm100
1 files changed, 49 insertions, 51 deletions
diff --git a/Log/Log4perl/Layout/Mozilla.pm b/Log/Log4perl/Layout/Mozilla.pm
index 4aedd9843..e523a3198 100644
--- a/Log/Log4perl/Layout/Mozilla.pm
+++ b/Log/Log4perl/Layout/Mozilla.pm
@@ -16,66 +16,64 @@ use constant LOGGING_FORMAT_VERSION => 2.0;
extends 'Log::Log4perl::Layout';
-has 'name' => (
- is => 'ro',
- default => 'Bugzilla',
-);
+has 'name' => (is => 'ro', default => 'Bugzilla',);
has 'max_json_length' => (
- is => 'ro',
- isa => sub { die "must be at least 1024\n" if $_[0] < 1024 },
- default => 4096,
+ is => 'ro',
+ isa => sub { die "must be at least 1024\n" if $_[0] < 1024 },
+ default => 4096,
);
sub BUILDARGS {
- my ($class, $params) = @_;
+ my ($class, $params) = @_;
- delete $params->{value};
- foreach my $key (keys %$params) {
- if (ref $params->{$key} eq 'HASH') {
- $params->{$key} = $params->{$key}{value};
- }
+ delete $params->{value};
+ foreach my $key (keys %$params) {
+ if (ref $params->{$key} eq 'HASH') {
+ $params->{$key} = $params->{$key}{value};
}
- return $params;
+ }
+ return $params;
}
sub render {
- my ( $self, $msg, $category, $priority, $caller_level ) = @_;
-
- state $HOSTNAME = hostname();
- state $JSON = JSON::MaybeXS->new(
- indent => 0, # to prevent newlines (and save space)
- ascii => 1, # to avoid encoding issues downstream
- allow_unknown => 1, # encode null on bad value (instead of exception)
- convert_blessed => 1, # call TO_JSON on blessed ref, if it exists
- allow_blessed => 1, # encode null on blessed ref that can't be converted
- );
-
- my $mdc = Log::Log4perl::MDC->get_context;
- my $fields = $mdc->{fields} // {};
- if ($mdc->{request_id}) {
- $fields->{request_id} = $mdc->{request_id}
- }
- my %out = (
- EnvVersion => LOGGING_FORMAT_VERSION,
- Hostname => $HOSTNAME,
- Logger => $self->name,
- Pid => $PID,
- Severity => $Log::Log4perl::Level::SYSLOG{$priority},
- Timestamp => time() * 1e9,
- Type => $category,
- Fields => { msg => $msg, %$fields },
- );
-
- my $json_text = $JSON->encode(\%out) . "\n";
- if (length($json_text) > $self->max_json_length) {
- my $scary_msg = sprintf 'DANGER! LOG MESSAGE TOO BIG %d > %d', length($json_text), $self->max_json_length;
- $out{Fields} = { remote_ip => $mdc->{remote_ip}, msg => $scary_msg };
- $out{Severity} = 1; # alert
- $json_text = $JSON->encode(\%out) . "\n";
- }
-
- return $json_text;
+ my ($self, $msg, $category, $priority, $caller_level) = @_;
+
+ state $HOSTNAME = hostname();
+ state $JSON = JSON::MaybeXS->new(
+ indent => 0, # to prevent newlines (and save space)
+ ascii => 1, # to avoid encoding issues downstream
+ allow_unknown => 1, # encode null on bad value (instead of exception)
+ convert_blessed => 1, # call TO_JSON on blessed ref, if it exists
+ allow_blessed => 1, # encode null on blessed ref that can't be converted
+ );
+
+ my $mdc = Log::Log4perl::MDC->get_context;
+ my $fields = $mdc->{fields} // {};
+ if ($mdc->{request_id}) {
+ $fields->{request_id} = $mdc->{request_id};
+ }
+ my %out = (
+ EnvVersion => LOGGING_FORMAT_VERSION,
+ Hostname => $HOSTNAME,
+ Logger => $self->name,
+ Pid => $PID,
+ Severity => $Log::Log4perl::Level::SYSLOG{$priority},
+ Timestamp => time() * 1e9,
+ Type => $category,
+ Fields => {msg => $msg, %$fields},
+ );
+
+ my $json_text = $JSON->encode(\%out) . "\n";
+ if (length($json_text) > $self->max_json_length) {
+ my $scary_msg = sprintf 'DANGER! LOG MESSAGE TOO BIG %d > %d',
+ length($json_text), $self->max_json_length;
+ $out{Fields} = {remote_ip => $mdc->{remote_ip}, msg => $scary_msg};
+ $out{Severity} = 1; # alert
+ $json_text = $JSON->encode(\%out) . "\n";
+ }
+
+ return $json_text;
}
1;
@@ -125,4 +123,4 @@ This is useful where some downstream system has a limit on the maximum size of
a message.
If the message is larger than this limit, the message will be replaced
-with a scary message at a severity level of ALERT. \ No newline at end of file
+with a scary message at a severity level of ALERT.