summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgregor herrmann <gregoa@debian.org>2023-09-03 21:18:26 +0200
committergregor herrmann <gregoa@debian.org>2023-09-03 21:18:26 +0200
commit2598b00b4b971e5b65015bbbb4af86e60b7cf55e (patch)
tree9624437657cab7af9c0f817ff7fe9aba3a30d94c
parent282ce75935e40e5434a69073efd17f5fb0c071a7 (diff)
parenta2abc631d6a3f48e82775db7a8f5416b39c306c3 (diff)
New upstream version 1.717
-rw-r--r--Changes19
-rw-r--r--META.json41
-rw-r--r--META.yml41
-rw-r--r--Makefile.PL2
-rw-r--r--lib/Log/Any.pm18
-rw-r--r--lib/Log/Any/Adapter.pm4
-rw-r--r--lib/Log/Any/Adapter/Base.pm4
-rw-r--r--lib/Log/Any/Adapter/Capture.pm4
-rw-r--r--lib/Log/Any/Adapter/Development.pod2
-rw-r--r--lib/Log/Any/Adapter/File.pm4
-rw-r--r--lib/Log/Any/Adapter/Multiplex.pm4
-rw-r--r--lib/Log/Any/Adapter/Null.pm4
-rw-r--r--lib/Log/Any/Adapter/Stderr.pm4
-rw-r--r--lib/Log/Any/Adapter/Stdout.pm4
-rw-r--r--lib/Log/Any/Adapter/Syslog.pm4
-rw-r--r--lib/Log/Any/Adapter/Test.pm4
-rw-r--r--lib/Log/Any/Adapter/Util.pm4
-rw-r--r--lib/Log/Any/Manager.pm4
-rw-r--r--lib/Log/Any/Proxy.pm4
-rw-r--r--lib/Log/Any/Proxy/Null.pm4
-rw-r--r--lib/Log/Any/Proxy/Test.pm4
-rw-r--r--lib/Log/Any/Proxy/WithStackTrace.pm209
-rw-r--r--lib/Log/Any/Test.pm4
-rw-r--r--t/proxy-with-stack-trace.t474
24 files changed, 676 insertions, 194 deletions
diff --git a/Changes b/Changes
index a4b9a65..0521b80 100644
--- a/Changes
+++ b/Changes
@@ -2,6 +2,25 @@ Revision history for Log-Any
** denotes an incompatible change
+1.717 2023-08-17 10:52:21-05:00 America/Chicago
+
+ [Fixed]
+
+ - Fixed WithStackTrace proxy to remove arguments in-place instead of
+ always stringifying the exception object immediately. This means we
+ need to handle different exception objects differently, but it also
+ means a better log message. Thanks @larryl and @GrantStreetGroup for
+ submitting this fix! [Github #100]
+
+1.716 2023-06-26 14:14:46-05:00 America/Chicago
+
+ [Added]
+
+ - Added a parameter to show stack trace arguments when using the
+ WithStackTrace proxy. Since these arguments may contain sensitive
+ information, they are now removed by default. Thanks @sam-ng and
+ @GrantStreetGroup for submitting this patch! [Github #97]
+
1.715 2023-05-04 13:09:22-05:00 America/Chicago
[Fixed]
diff --git a/META.json b/META.json
index c4d91c9..b9fe266 100644
--- a/META.json
+++ b/META.json
@@ -57,75 +57,75 @@
"provides" : {
"Log::Any" : {
"file" : "lib/Log/Any.pm",
- "version" : "1.715"
+ "version" : "1.717"
},
"Log::Any::Adapter" : {
"file" : "lib/Log/Any/Adapter.pm",
- "version" : "1.715"
+ "version" : "1.717"
},
"Log::Any::Adapter::Base" : {
"file" : "lib/Log/Any/Adapter/Base.pm",
- "version" : "1.715"
+ "version" : "1.717"
},
"Log::Any::Adapter::Capture" : {
"file" : "lib/Log/Any/Adapter/Capture.pm",
- "version" : "1.715"
+ "version" : "1.717"
},
"Log::Any::Adapter::File" : {
"file" : "lib/Log/Any/Adapter/File.pm",
- "version" : "1.715"
+ "version" : "1.717"
},
"Log::Any::Adapter::Multiplex" : {
"file" : "lib/Log/Any/Adapter/Multiplex.pm",
- "version" : "1.715"
+ "version" : "1.717"
},
"Log::Any::Adapter::Null" : {
"file" : "lib/Log/Any/Adapter/Null.pm",
- "version" : "1.715"
+ "version" : "1.717"
},
"Log::Any::Adapter::Stderr" : {
"file" : "lib/Log/Any/Adapter/Stderr.pm",
- "version" : "1.715"
+ "version" : "1.717"
},
"Log::Any::Adapter::Stdout" : {
"file" : "lib/Log/Any/Adapter/Stdout.pm",
- "version" : "1.715"
+ "version" : "1.717"
},
"Log::Any::Adapter::Syslog" : {
"file" : "lib/Log/Any/Adapter/Syslog.pm",
- "version" : "1.715"
+ "version" : "1.717"
},
"Log::Any::Adapter::Test" : {
"file" : "lib/Log/Any/Adapter/Test.pm",
- "version" : "1.715"
+ "version" : "1.717"
},
"Log::Any::Adapter::Util" : {
"file" : "lib/Log/Any/Adapter/Util.pm",
- "version" : "1.715"
+ "version" : "1.717"
},
"Log::Any::Manager" : {
"file" : "lib/Log/Any/Manager.pm",
- "version" : "1.715"
+ "version" : "1.717"
},
"Log::Any::Proxy" : {
"file" : "lib/Log/Any/Proxy.pm",
- "version" : "1.715"
+ "version" : "1.717"
},
"Log::Any::Proxy::Null" : {
"file" : "lib/Log/Any/Proxy/Null.pm",
- "version" : "1.715"
+ "version" : "1.717"
},
"Log::Any::Proxy::Test" : {
"file" : "lib/Log/Any/Proxy/Test.pm",
- "version" : "1.715"
+ "version" : "1.717"
},
"Log::Any::Proxy::WithStackTrace" : {
"file" : "lib/Log/Any/Proxy/WithStackTrace.pm",
- "version" : "1.715"
+ "version" : "1.717"
},
"Log::Any::Test" : {
"file" : "lib/Log/Any/Test.pm",
- "version" : "1.715"
+ "version" : "1.717"
}
},
"release_status" : "stable",
@@ -140,10 +140,11 @@
"web" : "https://github.com/preaction/Log-Any"
}
},
- "version" : "1.715",
+ "version" : "1.717",
"x_authority" : "cpan:PREACTION",
"x_contributors" : [
"Andrew Grechkin <andrew.grechkin@gmail.com>",
+ "Andrew Hewus Fresh <andrew+github@afresh1.com>",
"bj5004 <bartosz.jakubski@hurra.com>",
"cm-perl <cm-perl@users.noreply.github.com>",
"Doug Bell <preaction@users.noreply.github.com>",
@@ -161,6 +162,8 @@
"Paul Durden <alabamapaul@gmail.com>",
"Philipp Gortan <philipp.gortan@apa.at>",
"Phill Legault <saladdayllc@gmail.com>",
+ "Samuel Ng <samuel.ng@grantstreet.com>",
+ "Samuel Ng <sng@grantstreet.com>",
"Shlomi Fish <shlomif@shlomifish.org>",
"Sven Willenbuecher <sven.willenbuecher@kuehne-nagel.com>",
"XSven <XSven@users.noreply.github.com>"
diff --git a/META.yml b/META.yml
index c5c8a2e..84138fa 100644
--- a/META.yml
+++ b/META.yml
@@ -34,66 +34,67 @@ no_index:
provides:
Log::Any:
file: lib/Log/Any.pm
- version: '1.715'
+ version: '1.717'
Log::Any::Adapter:
file: lib/Log/Any/Adapter.pm
- version: '1.715'
+ version: '1.717'
Log::Any::Adapter::Base:
file: lib/Log/Any/Adapter/Base.pm
- version: '1.715'
+ version: '1.717'
Log::Any::Adapter::Capture:
file: lib/Log/Any/Adapter/Capture.pm
- version: '1.715'
+ version: '1.717'
Log::Any::Adapter::File:
file: lib/Log/Any/Adapter/File.pm
- version: '1.715'
+ version: '1.717'
Log::Any::Adapter::Multiplex:
file: lib/Log/Any/Adapter/Multiplex.pm
- version: '1.715'
+ version: '1.717'
Log::Any::Adapter::Null:
file: lib/Log/Any/Adapter/Null.pm
- version: '1.715'
+ version: '1.717'
Log::Any::Adapter::Stderr:
file: lib/Log/Any/Adapter/Stderr.pm
- version: '1.715'
+ version: '1.717'
Log::Any::Adapter::Stdout:
file: lib/Log/Any/Adapter/Stdout.pm
- version: '1.715'
+ version: '1.717'
Log::Any::Adapter::Syslog:
file: lib/Log/Any/Adapter/Syslog.pm
- version: '1.715'
+ version: '1.717'
Log::Any::Adapter::Test:
file: lib/Log/Any/Adapter/Test.pm
- version: '1.715'
+ version: '1.717'
Log::Any::Adapter::Util:
file: lib/Log/Any/Adapter/Util.pm
- version: '1.715'
+ version: '1.717'
Log::Any::Manager:
file: lib/Log/Any/Manager.pm
- version: '1.715'
+ version: '1.717'
Log::Any::Proxy:
file: lib/Log/Any/Proxy.pm
- version: '1.715'
+ version: '1.717'
Log::Any::Proxy::Null:
file: lib/Log/Any/Proxy/Null.pm
- version: '1.715'
+ version: '1.717'
Log::Any::Proxy::Test:
file: lib/Log/Any/Proxy/Test.pm
- version: '1.715'
+ version: '1.717'
Log::Any::Proxy::WithStackTrace:
file: lib/Log/Any/Proxy/WithStackTrace.pm
- version: '1.715'
+ version: '1.717'
Log::Any::Test:
file: lib/Log/Any/Test.pm
- version: '1.715'
+ version: '1.717'
resources:
bugtracker: https://github.com/preaction/Log-Any/issues
homepage: https://github.com/preaction/Log-Any
repository: https://github.com/preaction/Log-Any.git
-version: '1.715'
+version: '1.717'
x_authority: cpan:PREACTION
x_contributors:
- 'Andrew Grechkin <andrew.grechkin@gmail.com>'
+ - 'Andrew Hewus Fresh <andrew+github@afresh1.com>'
- 'bj5004 <bartosz.jakubski@hurra.com>'
- 'cm-perl <cm-perl@users.noreply.github.com>'
- 'Doug Bell <preaction@users.noreply.github.com>'
@@ -111,6 +112,8 @@ x_contributors:
- 'Paul Durden <alabamapaul@gmail.com>'
- 'Philipp Gortan <philipp.gortan@apa.at>'
- 'Phill Legault <saladdayllc@gmail.com>'
+ - 'Samuel Ng <samuel.ng@grantstreet.com>'
+ - 'Samuel Ng <sng@grantstreet.com>'
- 'Shlomi Fish <shlomif@shlomifish.org>'
- 'Sven Willenbuecher <sven.willenbuecher@kuehne-nagel.com>'
- 'XSven <XSven@users.noreply.github.com>'
diff --git a/Makefile.PL b/Makefile.PL
index 21a7486..3536ac9 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -23,7 +23,7 @@ my %WriteMakefileArgs = (
"IPC::Open3" => 0,
"Test::More" => 0
},
- "VERSION" => "1.715",
+ "VERSION" => "1.717",
"test" => {
"TESTS" => "t/*.t"
}
diff --git a/lib/Log/Any.pm b/lib/Log/Any.pm
index 532bb9f..029efa9 100644
--- a/lib/Log/Any.pm
+++ b/lib/Log/Any.pm
@@ -5,7 +5,7 @@ use warnings;
package Log::Any;
# ABSTRACT: Bringing loggers and listeners together
-our $VERSION = '1.715';
+our $VERSION = '1.717';
use Log::Any::Manager;
use Log::Any::Proxy::Null;
@@ -135,7 +135,7 @@ Log::Any - Bringing loggers and listeners together
=head1 VERSION
-version 1.715
+version 1.717
=head1 SYNOPSIS
@@ -478,7 +478,7 @@ Stephen Thirlwall <sdt@cpan.org>
=head1 CONTRIBUTORS
-=for stopwords Andrew Grechkin bj5004 cm-perl Doug Bell Jonathan Rubin Karen Etheridge Konstantin S. Uvarin Larry Leszczynski Lucas Kanashiro Maros Kollar Maxim Vuets mephinet Michael Conrad Nick Tonkin Paul Durden Philipp Gortan Phill Legault Shlomi Fish Sven Willenbuecher XSven
+=for stopwords Andrew Grechkin Hewus Fresh bj5004 cm-perl Doug Bell Jonathan Rubin Karen Etheridge Konstantin S. Uvarin Larry Leszczynski Lucas Kanashiro Maros Kollar Maxim Vuets mephinet Michael Conrad Nick Tonkin Paul Durden Philipp Gortan Phill Legault Samuel Ng Shlomi Fish Sven Willenbuecher XSven
=over 4
@@ -488,6 +488,10 @@ Andrew Grechkin <andrew.grechkin@gmail.com>
=item *
+Andrew Hewus Fresh <andrew+github@afresh1.com>
+
+=item *
+
bj5004 <bartosz.jakubski@hurra.com>
=item *
@@ -556,6 +560,14 @@ Phill Legault <saladdayllc@gmail.com>
=item *
+Samuel Ng <samuel.ng@grantstreet.com>
+
+=item *
+
+Samuel Ng <sng@grantstreet.com>
+
+=item *
+
Shlomi Fish <shlomif@shlomifish.org>
=item *
diff --git a/lib/Log/Any/Adapter.pm b/lib/Log/Any/Adapter.pm
index 086fba7..65eda7c 100644
--- a/lib/Log/Any/Adapter.pm
+++ b/lib/Log/Any/Adapter.pm
@@ -5,7 +5,7 @@ use warnings;
package Log::Any::Adapter;
# ABSTRACT: Tell Log::Any where to send its logs
-our $VERSION = '1.715';
+our $VERSION = '1.717';
use Log::Any;
our @CARP_NOT = ( 'Log::Any::Manager' );
@@ -44,7 +44,7 @@ Log::Any::Adapter - Tell Log::Any where to send its logs
=head1 VERSION
-version 1.715
+version 1.717
=head1 SYNOPSIS
diff --git a/lib/Log/Any/Adapter/Base.pm b/lib/Log/Any/Adapter/Base.pm
index 2bbce9e..c8ca130 100644
--- a/lib/Log/Any/Adapter/Base.pm
+++ b/lib/Log/Any/Adapter/Base.pm
@@ -4,7 +4,7 @@ use warnings;
package Log::Any::Adapter::Base;
-our $VERSION = '1.715';
+our $VERSION = '1.717';
our @CARP_NOT = ( 'Log::Any::Adapter' );
# we import these in case any legacy adapter uses them as class methods
@@ -52,7 +52,7 @@ Log::Any::Adapter::Base
=head1 VERSION
-version 1.715
+version 1.717
=head1 AUTHORS
diff --git a/lib/Log/Any/Adapter/Capture.pm b/lib/Log/Any/Adapter/Capture.pm
index 7769bdb..4a05bfc 100644
--- a/lib/Log/Any/Adapter/Capture.pm
+++ b/lib/Log/Any/Adapter/Capture.pm
@@ -5,7 +5,7 @@ use warnings;
package Log::Any::Adapter::Capture;
# ABSTRACT: Adapter for capturing log messages into an arrayref
-our $VERSION = '1.715';
+our $VERSION = '1.717';
use Log::Any::Adapter::Util ();
@@ -114,7 +114,7 @@ Log::Any::Adapter::Capture - Adapter for capturing log messages into an arrayref
=head1 VERSION
-version 1.715
+version 1.717
=head1 SYNOPSIS
diff --git a/lib/Log/Any/Adapter/Development.pod b/lib/Log/Any/Adapter/Development.pod
index 4845a30..84b87f7 100644
--- a/lib/Log/Any/Adapter/Development.pod
+++ b/lib/Log/Any/Adapter/Development.pod
@@ -16,7 +16,7 @@ Log::Any::Adapter::Development - Manual for developing new Log::Any adapters
=head1 VERSION
-version 1.715
+version 1.717
=head1 SYNOPSIS
diff --git a/lib/Log/Any/Adapter/File.pm b/lib/Log/Any/Adapter/File.pm
index b415eca..373585e 100644
--- a/lib/Log/Any/Adapter/File.pm
+++ b/lib/Log/Any/Adapter/File.pm
@@ -5,7 +5,7 @@ use warnings;
package Log::Any::Adapter::File;
# ABSTRACT: Simple adapter for logging to files
-our $VERSION = '1.715';
+our $VERSION = '1.717';
use Config;
use Fcntl qw/:flock/;
@@ -80,7 +80,7 @@ Log::Any::Adapter::File - Simple adapter for logging to files
=head1 VERSION
-version 1.715
+version 1.717
=head1 SYNOPSIS
diff --git a/lib/Log/Any/Adapter/Multiplex.pm b/lib/Log/Any/Adapter/Multiplex.pm
index bd13e40..f994d56 100644
--- a/lib/Log/Any/Adapter/Multiplex.pm
+++ b/lib/Log/Any/Adapter/Multiplex.pm
@@ -1,6 +1,6 @@
package Log::Any::Adapter::Multiplex;
# ABSTRACT: Adapter to use allow structured logging across other adapters
-our $VERSION = '1.715';
+our $VERSION = '1.717';
use Log::Any;
use Log::Any::Adapter;
@@ -115,7 +115,7 @@ Log::Any::Adapter::Multiplex - Adapter to use allow structured logging across ot
=head1 VERSION
-version 1.715
+version 1.717
=head1 SYNOPSIS
diff --git a/lib/Log/Any/Adapter/Null.pm b/lib/Log/Any/Adapter/Null.pm
index 59cac16..87ea86f 100644
--- a/lib/Log/Any/Adapter/Null.pm
+++ b/lib/Log/Any/Adapter/Null.pm
@@ -5,7 +5,7 @@ use warnings;
package Log::Any::Adapter::Null;
# ABSTRACT: Discards all log messages
-our $VERSION = '1.715';
+our $VERSION = '1.717';
use Log::Any::Adapter::Base;
our @ISA = qw/Log::Any::Adapter::Base/;
@@ -33,7 +33,7 @@ Log::Any::Adapter::Null - Discards all log messages
=head1 VERSION
-version 1.715
+version 1.717
=head1 SYNOPSIS
diff --git a/lib/Log/Any/Adapter/Stderr.pm b/lib/Log/Any/Adapter/Stderr.pm
index 768483f..22a7a78 100644
--- a/lib/Log/Any/Adapter/Stderr.pm
+++ b/lib/Log/Any/Adapter/Stderr.pm
@@ -5,7 +5,7 @@ use warnings;
package Log::Any::Adapter::Stderr;
# ABSTRACT: Simple adapter for logging to STDERR
-our $VERSION = '1.715';
+our $VERSION = '1.717';
use Log::Any::Adapter::Util ();
@@ -62,7 +62,7 @@ Log::Any::Adapter::Stderr - Simple adapter for logging to STDERR
=head1 VERSION
-version 1.715
+version 1.717
=head1 SYNOPSIS
diff --git a/lib/Log/Any/Adapter/Stdout.pm b/lib/Log/Any/Adapter/Stdout.pm
index e75d19c..7869ffa 100644
--- a/lib/Log/Any/Adapter/Stdout.pm
+++ b/lib/Log/Any/Adapter/Stdout.pm
@@ -5,7 +5,7 @@ use warnings;
package Log::Any::Adapter::Stdout;
# ABSTRACT: Simple adapter for logging to STDOUT
-our $VERSION = '1.715';
+our $VERSION = '1.717';
use Log::Any::Adapter::Util ();
@@ -62,7 +62,7 @@ Log::Any::Adapter::Stdout - Simple adapter for logging to STDOUT
=head1 VERSION
-version 1.715
+version 1.717
=head1 SYNOPSIS
diff --git a/lib/Log/Any/Adapter/Syslog.pm b/lib/Log/Any/Adapter/Syslog.pm
index abb29e6..e3e984e 100644
--- a/lib/Log/Any/Adapter/Syslog.pm
+++ b/lib/Log/Any/Adapter/Syslog.pm
@@ -5,7 +5,7 @@ use warnings;
package Log::Any::Adapter::Syslog;
# ABSTRACT: Send Log::Any logs to syslog
-our $VERSION = '1.715';
+our $VERSION = '1.717';
use Log::Any::Adapter::Util qw{make_method};
use base qw{Log::Any::Adapter::Base};
@@ -151,7 +151,7 @@ Log::Any::Adapter::Syslog - Send Log::Any logs to syslog
=head1 VERSION
-version 1.715
+version 1.717
=head1 SYNOPSIS
diff --git a/lib/Log/Any/Adapter/Test.pm b/lib/Log/Any/Adapter/Test.pm
index 9ca9fa4..fffe7ba 100644
--- a/lib/Log/Any/Adapter/Test.pm
+++ b/lib/Log/Any/Adapter/Test.pm
@@ -4,7 +4,7 @@ use warnings;
package Log::Any::Adapter::Test;
-our $VERSION = '1.715';
+our $VERSION = '1.717';
use Log::Any::Adapter::Util qw/dump_one_line/;
use Test::Builder;
@@ -218,7 +218,7 @@ Log::Any::Adapter::Test
=head1 VERSION
-version 1.715
+version 1.717
=head1 AUTHORS
diff --git a/lib/Log/Any/Adapter/Util.pm b/lib/Log/Any/Adapter/Util.pm
index 535bf33..91142e7 100644
--- a/lib/Log/Any/Adapter/Util.pm
+++ b/lib/Log/Any/Adapter/Util.pm
@@ -5,7 +5,7 @@ use warnings;
package Log::Any::Adapter::Util;
# ABSTRACT: Common utility functions for Log::Any
-our $VERSION = '1.715';
+our $VERSION = '1.717';
use Exporter;
our @ISA = qw/Exporter/;
@@ -241,7 +241,7 @@ Log::Any::Adapter::Util - Common utility functions for Log::Any
=head1 VERSION
-version 1.715
+version 1.717
=head1 DESCRIPTION
diff --git a/lib/Log/Any/Manager.pm b/lib/Log/Any/Manager.pm
index e680390..4a25579 100644
--- a/lib/Log/Any/Manager.pm
+++ b/lib/Log/Any/Manager.pm
@@ -4,7 +4,7 @@ use warnings;
package Log::Any::Manager;
-our $VERSION = '1.715';
+our $VERSION = '1.717';
sub new {
my $class = shift;
@@ -248,7 +248,7 @@ Log::Any::Manager
=head1 VERSION
-version 1.715
+version 1.717
=head1 AUTHORS
diff --git a/lib/Log/Any/Proxy.pm b/lib/Log/Any/Proxy.pm
index d7e3a50..44dcfa0 100644
--- a/lib/Log/Any/Proxy.pm
+++ b/lib/Log/Any/Proxy.pm
@@ -5,7 +5,7 @@ use warnings;
package Log::Any::Proxy;
# ABSTRACT: Log::Any generator proxy object
-our $VERSION = '1.715';
+our $VERSION = '1.717';
use Log::Any::Adapter::Util ();
use overload;
@@ -150,7 +150,7 @@ Log::Any::Proxy - Log::Any generator proxy object
=head1 VERSION
-version 1.715
+version 1.717
=head1 SYNOPSIS
diff --git a/lib/Log/Any/Proxy/Null.pm b/lib/Log/Any/Proxy/Null.pm
index edc0c3c..b0e776d 100644
--- a/lib/Log/Any/Proxy/Null.pm
+++ b/lib/Log/Any/Proxy/Null.pm
@@ -5,7 +5,7 @@ use warnings;
package Log::Any::Proxy::Null;
# ABSTRACT: Log::Any generator proxy for no adapters
-our $VERSION = '1.715';
+our $VERSION = '1.717';
use Log::Any::Adapter::Util ();
use Log::Any::Proxy;
@@ -57,7 +57,7 @@ Log::Any::Proxy::Null - Log::Any generator proxy for no adapters
=head1 VERSION
-version 1.715
+version 1.717
=head1 AUTHORS
diff --git a/lib/Log/Any/Proxy/Test.pm b/lib/Log/Any/Proxy/Test.pm
index f8e2a99..c9ef9a7 100644
--- a/lib/Log/Any/Proxy/Test.pm
+++ b/lib/Log/Any/Proxy/Test.pm
@@ -4,7 +4,7 @@ use warnings;
package Log::Any::Proxy::Test;
-our $VERSION = '1.715';
+our $VERSION = '1.717';
use Log::Any::Proxy;
our @ISA = qw/Log::Any::Proxy/;
@@ -42,7 +42,7 @@ Log::Any::Proxy::Test
=head1 VERSION
-version 1.715
+version 1.717
=head1 AUTHORS
diff --git a/lib/Log/Any/Proxy/WithStackTrace.pm b/lib/Log/Any/Proxy/WithStackTrace.pm
index 3f4389d..f9dcd7c 100644
--- a/lib/Log/Any/Proxy/WithStackTrace.pm
+++ b/lib/Log/Any/Proxy/WithStackTrace.pm
@@ -5,26 +5,31 @@ use warnings;
package Log::Any::Proxy::WithStackTrace;
# ABSTRACT: Log::Any proxy to upgrade string errors to objects with stack traces
-our $VERSION = '1.715';
+our $VERSION = '1.717';
use Log::Any::Proxy;
our @ISA = qw/Log::Any::Proxy/;
use Devel::StackTrace 2.00;
use Log::Any::Adapter::Util ();
+use Scalar::Util qw/blessed reftype/;
use overload;
#pod =head1 SYNOPSIS
#pod
#pod use Log::Any qw( $log, proxy_class => 'WithStackTrace' );
#pod
-#pod # Some adapter that knows how to handle both structured data,
-#pod # and log messages which are actually objects with a
-#pod # "stack_trace" method:
-#pod #
+#pod # Allow stack trace call stack arguments to be logged:
+#pod use Log::Any qw( $log, proxy_class => 'WithStackTrace',
+#pod proxy_show_stack_trace_args => 1 );
+#pod
+#pod # Configure some adapter that knows how to:
+#pod # 1) handle structured data, and
+#pod # 2) handle message objects which have a "stack_trace" method:
#pod Log::Any::Adapter->set($adapter);
#pod
-#pod $log->error("Help!"); # stack trace gets automatically added
+#pod $log->error("Help!"); # stack trace gets automatically added,
+#pod # starting from this line of code
#pod
#pod =head1 DESCRIPTION
#pod
@@ -35,12 +40,20 @@ use overload;
#pod relative to where the log adapter was called, and not relative to where
#pod the logging method was originally called.
#pod
-#pod With this proxy in place, if any logging method is called with a message
-#pod that is a non-reference scalar, that message will be upgraded into a
-#pod C<Log::Any::MessageWithStackTrace> object with a C<stack_trace> method,
-#pod and that method will return a trace relative to where the logging method
-#pod was called. A string overload is provided on the object to return the
-#pod original message.
+#pod With this proxy in place, if any logging method is called with a log
+#pod message that is a non-reference scalar (i.e. a string), that log message
+#pod will be upgraded into a C<Log::Any::MessageWithStackTrace> object with a
+#pod C<stack_trace> method, and that method will return a trace relative to
+#pod where the logging method was called. A string overload is provided on
+#pod the object to return the original log message.
+#pod
+#pod Additionally, any call stack arguments in the stack trace will be
+#pod deleted before logging, to avoid accidentally logging sensitive data.
+#pod This happens both for message objects that were auto-generated from
+#pod string messages, as well as for message objects that were passed in
+#pod directly (if they appear to have a stack trace method). This default
+#pod argument scrubbing behavior can be turned off by specifying a true value
+#pod for the C<proxy_show_stack_trace_args> import flag.
#pod
#pod B<Important:> This proxy should be used with a L<Log::Any::Adapter> that
#pod is configured to handle structured data. Otherwise the object created
@@ -55,17 +68,16 @@ use overload;
use overload '""' => \&stringify;
- use Carp qw( croak );
-
sub new
{
- my ($class, $message) = @_;
- croak 'no "message"' unless defined $message;
+ my ($class, $message, %opts) = @_;
+
return bless {
message => $message,
stack_trace => Devel::StackTrace->new(
# Filter e.g "Log::Any::Proxy", "My::Log::Any::Proxy", etc.
ignore_package => [ qr/(?:^|::)Log::Any(?:::|$)/ ],
+ no_args => $opts{no_args},
),
}, $class;
}
@@ -79,29 +91,89 @@ use overload;
#pod
#pod =head2 maybe_upgrade_with_stack_trace
#pod
-#pod This is an internal use method that will convert a non-reference scalar
+#pod @args = $self->maybe_upgrade_with_stack_trace(@args);
+#pod
+#pod This is an internal-use method that will convert a non-reference scalar
#pod message into a C<Log::Any::MessageWithStackTrace> object with a
#pod C<stack_trace> method. A string overload is provided to return the
#pod original message.
#pod
+#pod Stack trace args are scrubbed out in case they contain sensitive data,
+#pod unless the C<proxy_show_stack_trace_args> option has been set.
+#pod
#pod =cut
sub maybe_upgrade_with_stack_trace
{
my ($self, @args) = @_;
- # Only want a non-ref arg, optionally followed by a structured data
- # context hashref:
- #
+ # We expect a message, optionally followed by a structured data
+ # context hashref. Bail if we get anything other than that rather
+ # than guess what the caller might be trying to do:
return @args unless @args == 1 ||
( @args == 2 && ref $args[1] eq 'HASH' );
- return @args if ref $args[0];
- $args[0] = Log::Any::MessageWithStackTrace->new($args[0]);
+ if (ref $args[0]) {
+ $self->maybe_delete_stack_trace_args($args[0])
+ unless $self->{proxy_show_stack_trace_args};
+ }
+ else {
+ $args[0] = Log::Any::MessageWithStackTrace->new(
+ $args[0],
+ no_args => !$self->{proxy_show_stack_trace_args},
+ );
+ }
return @args;
}
+#pod =head2 maybe_delete_stack_trace_args
+#pod
+#pod $self->maybe_delete_stack_trace_args($arg);
+#pod
+#pod This is an internal-use method that, given a single argument that is a
+#pod reference, tries to figure out whether the argument is an object with a
+#pod stack trace, and if so tries to delete any stack trace args.
+#pod
+#pod The logic is based on L<Devel::StackTrace::Extract>.
+#pod
+#pod It specifically looks for objects with a C<stack_trace> method (which
+#pod should catch anything that does L<StackTrace::Auto>, including anything
+#pod that does L<Throwable::Error>), or a C<trace> method (used by
+#pod L<Exception::Class> and L<Moose::Exception> and friends).
+#pod
+#pod It specifically ignores L<Mojo::Exception> objects, because their stack
+#pod traces don't contain any call stack args.
+#pod
+#pod =cut
+
+sub maybe_delete_stack_trace_args
+{
+ my ($self, $arg) = @_;
+
+ return unless blessed $arg;
+
+ if ($arg->can('stack_trace')) {
+ # This should catch anything that does StackTrace::Auto,
+ # including anything that does Throwable::Error.
+ my $trace = $arg->stack_trace;
+ $self->delete_args_from_stack_trace($trace);
+ }
+ elsif ($arg->isa('Mojo::Exception')) {
+ # Skip these, they don't have args in their stack traces.
+ }
+ elsif ($arg->can('trace')) {
+ # This should catch Exception::Class and Moose::Exception and
+ # friends. Make sure to check for the "trace" method *after*
+ # skipping the Mojo::Exception objects, because those also have
+ # a "trace" method.
+ my $trace = $arg->trace;
+ $self->delete_args_from_stack_trace($trace);
+ }
+
+ return;
+}
+
my %aliases = Log::Any::Adapter::Util::log_level_aliases();
# Set up methods/aliases and detection methods/aliases
@@ -118,6 +190,30 @@ foreach my $name ( Log::Any::Adapter::Util::logging_methods(), keys(%aliases) )
};
}
+#pod =head2 delete_args_from_stack_trace($trace)
+#pod
+#pod $self->delete_args_from_stack_trace($trace)
+#pod
+#pod To scrub potentially sensitive data from C<Devel::StackTrace> arguments,
+#pod this method deletes arguments from all of the C<Devel::StackTrace::Frame>
+#pod in the trace.
+#pod
+#pod =cut
+
+sub delete_args_from_stack_trace
+{
+ my ($self, $trace) = @_;
+
+ return unless $trace && $trace->can('frames');
+
+ foreach my $frame ($trace->frames) {
+ next unless $frame->{args};
+ $frame->{args} = [];
+ }
+
+ return;
+}
+
1;
__END__
@@ -132,19 +228,23 @@ Log::Any::Proxy::WithStackTrace - Log::Any proxy to upgrade string errors to obj
=head1 VERSION
-version 1.715
+version 1.717
=head1 SYNOPSIS
use Log::Any qw( $log, proxy_class => 'WithStackTrace' );
- # Some adapter that knows how to handle both structured data,
- # and log messages which are actually objects with a
- # "stack_trace" method:
- #
+ # Allow stack trace call stack arguments to be logged:
+ use Log::Any qw( $log, proxy_class => 'WithStackTrace',
+ proxy_show_stack_trace_args => 1 );
+
+ # Configure some adapter that knows how to:
+ # 1) handle structured data, and
+ # 2) handle message objects which have a "stack_trace" method:
Log::Any::Adapter->set($adapter);
- $log->error("Help!"); # stack trace gets automatically added
+ $log->error("Help!"); # stack trace gets automatically added,
+ # starting from this line of code
=head1 DESCRIPTION
@@ -155,12 +255,20 @@ used to generate one, the resulting trace can be confusing if it begins
relative to where the log adapter was called, and not relative to where
the logging method was originally called.
-With this proxy in place, if any logging method is called with a message
-that is a non-reference scalar, that message will be upgraded into a
-C<Log::Any::MessageWithStackTrace> object with a C<stack_trace> method,
-and that method will return a trace relative to where the logging method
-was called. A string overload is provided on the object to return the
-original message.
+With this proxy in place, if any logging method is called with a log
+message that is a non-reference scalar (i.e. a string), that log message
+will be upgraded into a C<Log::Any::MessageWithStackTrace> object with a
+C<stack_trace> method, and that method will return a trace relative to
+where the logging method was called. A string overload is provided on
+the object to return the original log message.
+
+Additionally, any call stack arguments in the stack trace will be
+deleted before logging, to avoid accidentally logging sensitive data.
+This happens both for message objects that were auto-generated from
+string messages, as well as for message objects that were passed in
+directly (if they appear to have a stack trace method). This default
+argument scrubbing behavior can be turned off by specifying a true value
+for the C<proxy_show_stack_trace_args> import flag.
B<Important:> This proxy should be used with a L<Log::Any::Adapter> that
is configured to handle structured data. Otherwise the object created
@@ -171,11 +279,42 @@ trace.
=head2 maybe_upgrade_with_stack_trace
-This is an internal use method that will convert a non-reference scalar
+ @args = $self->maybe_upgrade_with_stack_trace(@args);
+
+This is an internal-use method that will convert a non-reference scalar
message into a C<Log::Any::MessageWithStackTrace> object with a
C<stack_trace> method. A string overload is provided to return the
original message.
+Stack trace args are scrubbed out in case they contain sensitive data,
+unless the C<proxy_show_stack_trace_args> option has been set.
+
+=head2 maybe_delete_stack_trace_args
+
+ $self->maybe_delete_stack_trace_args($arg);
+
+This is an internal-use method that, given a single argument that is a
+reference, tries to figure out whether the argument is an object with a
+stack trace, and if so tries to delete any stack trace args.
+
+The logic is based on L<Devel::StackTrace::Extract>.
+
+It specifically looks for objects with a C<stack_trace> method (which
+should catch anything that does L<StackTrace::Auto>, including anything
+that does L<Throwable::Error>), or a C<trace> method (used by
+L<Exception::Class> and L<Moose::Exception> and friends).
+
+It specifically ignores L<Mojo::Exception> objects, because their stack
+traces don't contain any call stack args.
+
+=head2 delete_args_from_stack_trace($trace)
+
+ $self->delete_args_from_stack_trace($trace)
+
+To scrub potentially sensitive data from C<Devel::StackTrace> arguments,
+this method deletes arguments from all of the C<Devel::StackTrace::Frame>
+in the trace.
+
=head1 AUTHORS
=over 4
diff --git a/lib/Log/Any/Test.pm b/lib/Log/Any/Test.pm
index 633cf4d..3f70b90 100644
--- a/lib/Log/Any/Test.pm
+++ b/lib/Log/Any/Test.pm
@@ -5,7 +5,7 @@ use warnings;
package Log::Any::Test;
# ABSTRACT: Test what you're logging with Log::Any
-our $VERSION = '1.715';
+our $VERSION = '1.717';
no warnings 'once';
$Log::Any::OverrideDefaultAdapterClass = 'Log::Any::Adapter::Test';
@@ -25,7 +25,7 @@ Log::Any::Test - Test what you're logging with Log::Any
=head1 VERSION
-version 1.715
+version 1.717
=head1 SYNOPSIS
diff --git a/t/proxy-with-stack-trace.t b/t/proxy-with-stack-trace.t
index 3f69917..4d49b63 100644
--- a/t/proxy-with-stack-trace.t
+++ b/t/proxy-with-stack-trace.t
@@ -2,138 +2,444 @@
use strict;
use warnings;
use Test::More;
+use List::Util qw( any );
use Log::Any;
-
-plan tests => 48;
+use Scalar::Util qw( blessed );
+use Storable qw( dclone );
use FindBin;
use lib $FindBin::RealBin;
use TestAdapters;
+my (
+ $num_tests,
+ $have_Mojo_Exception,
+ $have_Moose_Exception,
+ $have_Throwable_Error,
+);
BEGIN {
+
+ $num_tests = 152;
+ eval {
+ require Mojo::Exception;
+ $have_Mojo_Exception = 1;
+ $num_tests += 27;
+ };
+ eval {
+ require Throwable::Error;
+ $have_Throwable_Error = 1;
+ $num_tests += 31;
+ };
+ eval {
+ require Moose::Exception;
+ $have_Moose_Exception = 1;
+ $num_tests += 31;
+ };
+
eval {
require Devel::StackTrace;
Devel::StackTrace->VERSION( 2.00 );
};
if ( $@ ) {
plan skip_all => 'Devel::StackTrace >= 2.00 is required for this test';
- }
- else {
- eval {
- require Storable;
- Storable->VERSION( 3.08 );
- };
- if ( $@ ) {
- plan skip_all => 'Storable >= 3.08 is required for this test';
- }
+ $num_tests = 0;
}
}
+plan tests => $num_tests if $num_tests;
+
use Log::Any::Proxy::WithStackTrace; # necessary?
-my $default_log = Log::Any->get_logger;
-my $log = Log::Any->get_logger( proxy_class => 'WithStackTrace' );
+my $default_log = Log::Any->get_logger;
+my $log = Log::Any->get_logger( proxy_class => 'WithStackTrace' );
+my $log_show_args = Log::Any->get_logger( proxy_class => 'WithStackTrace', proxy_show_stack_trace_args => 1);
-is ref $default_log, 'Log::Any::Proxy::Null',
+is ref $default_log, 'Log::Any::Proxy::Null',
'no adapter default proxy is Null';
-is ref $log, 'Log::Any::Proxy::WithStackTrace',
+is ref $log, 'Log::Any::Proxy::WithStackTrace',
'no adapter explicit proxy is WithStackTrace';
+is ref $log_show_args, 'Log::Any::Proxy::WithStackTrace',
+ 'no adapter explicit proxy with proxy_show_stack_trace_args flag is WithStackTrace';
-$default_log->info("test");
-$log ->info("test");
+$default_log ->info("test");
+$log ->info("test");
+$log_show_args->info("test");
-is ref $default_log, 'Log::Any::Proxy::Null',
+is ref $default_log, 'Log::Any::Proxy::Null',
'no adapter default proxy is still Null after logging';
-is ref $log, 'Log::Any::Proxy::WithStackTrace',
+is ref $log, 'Log::Any::Proxy::WithStackTrace',
'no adapter explicit proxy is still WithStackTrace after logging';
+is ref $log_show_args, 'Log::Any::Proxy::WithStackTrace',
+ 'no adapter explicit proxy with proxy_show_stack_trace_args flag is still WithStackTrace after logging';
Log::Any->set_adapter('+TestAdapters::Structured');
-is ref $default_log, 'Log::Any::Proxy',
+is ref $default_log, 'Log::Any::Proxy',
'existing default proxy is reblessed after adapter';
-is ref $log, 'Log::Any::Proxy::WithStackTrace',
+is !!$default_log->{proxy_show_stack_trace_args}, '',
+ 'Defauly log does not proxy_show_stack_trace_args';
+is ref $log, 'Log::Any::Proxy::WithStackTrace',
'existing explicit proxy is still WithStackTrace after adapter';
+is !!$log->{proxy_show_stack_trace_args}, '',
+ 'WithStackTrace does not proxy_show_stack_trace_args';
+is ref $log_show_args, 'Log::Any::Proxy::WithStackTrace',
+ 'existing explicit proxy with proxy_show_stack_trace_args flag is still WithStackTrace after adapter';
+is !!$log_show_args->{proxy_show_stack_trace_args}, 1,
+ 'WithStackTrace does proxy_show_stack_trace_args';
-is ref $default_log->adapter, 'TestAdapters::Structured',
+is ref $default_log->adapter, 'TestAdapters::Structured',
'existing default proxy has correct adapter';
-is ref $log->adapter, 'TestAdapters::Structured',
+is ref $log->adapter, 'TestAdapters::Structured',
'existing explicit proxy has correct adapter';
+is ref $log_show_args->adapter, 'TestAdapters::Structured',
+ 'existing explicit proxy with proxy_show_stack_trace_args flag has correct adapter';
+
+###################################################################
+
+# Dummy default for initial call:
+my $logger = $default_log;
+my $message = "dummy";
+my $extra_args = [];
+
+my ($Mojo_Exception, $Moose_Exception, $Throwable_Error);
+
+sub foo
+{
+ sub bar {
+
+ # Log with a stack trace that is 3 frames deep (main->foo->bar):
+ $logger->info($message, @$extra_args);
+
+ # Create a Mojo::Exception with a similar stack trace:
+ if ($have_Mojo_Exception && !$Mojo_Exception) {
+ local $@;
+ eval { Mojo::Exception->throw("Help!") };
+ $Mojo_Exception = $@;
+ }
+
+ # Create a Moose::Exception with a similar stack trace:
+ if ($have_Moose_Exception && !$Moose_Exception) {
+ $Moose_Exception = Moose::Exception->new(message => "Help!");
+ }
+
+ # Create a Throwable::Error with a similar stack trace:
+ if ($have_Throwable_Error && !$Throwable_Error) {
+ local $@;
+ eval { Throwable::Error->throw("Help!") };
+ $Throwable_Error = $@;
+ # Default log adapter doesn't like coderefs:
+ $Throwable_Error->stack_trace->{frame_filter} = undef;
+ $Throwable_Error->{stack_trace_args} = undef;
+ }
+ }
+
+ bar("quux");
+}
+
+# Make sure exception objects get initialized:
+foo("bar", "baz") if $have_Mojo_Exception ||
+ $have_Moose_Exception ||
+ $have_Throwable_Error;
-my @test_cases = (
+my ($desc, $expected_by_type);
+
+foreach my $t (
[
- 'simple',
- [ 'test' ],
- 'test',
+ "with string",
+ "Help!",
+ [],
+ {
+ "default log" => "Help!",
+ "proxy log" => [
+ "Help!",
+ "Log::Any::MessageWithStackTrace",
+ ],
+ "proxy log show args" => [
+ "Help!",
+ "Log::Any::MessageWithStackTrace",
+ ],
+ },
],
[
- 'with structured data',
- [ 'test', { foo => 1 } ],
- 'test',
+ "with string and extra args",
+ "Help!",
+ [ {extra => "data"} ],
+ {
+ "default log" => "Help!",
+ "proxy log" => [
+ "Help!",
+ "Log::Any::MessageWithStackTrace",
+ ],
+ "proxy log show args" => [
+ "Help!",
+ "Log::Any::MessageWithStackTrace",
+ ],
+ },
],
[
- 'formatted',
- [ 'test %s', 'extra' ],
- 'test extra',
+ "with string and bad extra args",
+ "Help!",
+ [ {extra => "data"}, "huh?" ],
+ {
+ "default log" => "Help!",
+ # no automatic object inflation if unexpected args:
+ "proxy log" => "Help!",
+ "proxy log show args" => "Help!",
+ },
],
-);
-
-sub check_test_cases {
- foreach my $test_case (@test_cases) {
- my ($desc, $args, $expected) = @$test_case;
+ [
+ "with string and bad non-hashref extra args",
+ "Help!",
+ [ "huh?" ],
+ {
+ "default log" => "Help!",
+ # no automatic object inflation if unexpected args:
+ "proxy log" => "Help!",
+ "proxy log show args" => "Help!",
+ },
+ ],
+ [
+ "with non-string unblessed message",
+ {foo => "bar"},
+ [],
+ {
+ "default log" => [
+ {foo => "bar"},
+ "HASH",
+ ],
+ # no automatic object inflation if non-string message:
+ "proxy log" => [
+ {foo => "bar"},
+ "HASH",
+ ],
+ "proxy log show args" => [
+ {foo => "bar"},
+ "HASH",
+ ],
+ },
+ ],
+ [
+ "with dummy blessed object",
+ bless({foo => "bar"}, "DummyError"),
+ [],
+ {
+ "default log" => [
+ qr{^DummyError=HASH\(0x[0-9a-f]+\)},
+ "DummyError",
+ ],
+ # no automatic object inflation if random blessed message:
+ "proxy log" => [
+ qr{^DummyError=HASH\(0x[0-9a-f]+\)},
+ "DummyError",
+ ],
+ "proxy log show args" => [
+ qr{^DummyError=HASH\(0x[0-9a-f]+\)},
+ "DummyError",
+ ],
+ },
+ ],
+ [
+ "with Mojo::Exception message",
+ $Mojo_Exception,
+ [],
+ {
+ "default log" => [
+ qr{^Help! at t/proxy-with-stack-trace\.t line \d+\.},
+ "Mojo::Exception",
+ ],
+ "proxy log" => [
+ qr{^Help! at t/proxy-with-stack-trace\.t line \d+\.},
+ "Mojo::Exception",
+ ],
+ "proxy log show args" => [
+ qr{^Help! at t/proxy-with-stack-trace\.t line \d+\.},
+ "Mojo::Exception",
+ ],
+ },
+ ],
+ [
+ "with Moose::Exception message",
+ $Moose_Exception,
+ [],
+ {
+ "default log" => [
+ qr{^Help! at t/proxy-with-stack-trace\.t line \d+\n},
+ "Moose::Exception",
+ ],
+ "proxy log" => [
+ qr{^Help! at t/proxy-with-stack-trace\.t line \d+\n},
+ "Moose::Exception",
+ ],
+ "proxy log show args" => [
+ qr{^Help! at t/proxy-with-stack-trace\.t line \d+\n},
+ "Moose::Exception",
+ ],
+ },
+ ],
+ [
+ "with Throwable::Error message",
+ $Throwable_Error,
+ [],
+ {
+ "default log" => [
+ qr{^Help!\n\nTrace begun at t/proxy-with-stack-trace\.t line \d+\n},
+ "Throwable::Error",
+ ],
+ "proxy log" => [
+ qr{^Help!\n\nTrace begun at t/proxy-with-stack-trace\.t line \d+\n},
+ "Throwable::Error",
+ ],
+ "proxy log show args" => [
+ qr{^Help!\n\nTrace begun at t/proxy-with-stack-trace\.t line \d+\n},
+ "Throwable::Error",
+ ],
+ },
+ ],
+) {
+ my $orig_message;
+ ($desc, $orig_message, $extra_args, $expected_by_type) = @$t;
- my $is_formatted = $args->[0] =~ /%/;
+ # This can happen if one of the optional exception modules is not
+ # loaded:
+ next unless $orig_message;
- my $method = $is_formatted ? 'infof' : 'info';
+ foreach my $type (sort keys %$expected_by_type) {
- my ($msgs, $msg);
+ $message = ref $orig_message ? dclone $orig_message : $orig_message;
- my $type = 'default';
+ $logger = {
+ "default log" => $default_log,
+ "proxy log" => $log,
+ "proxy log show args" => $log_show_args,
+ }->{$type};
@TestAdapters::STRUCTURED_LOG = ();
- $default_log->$method(@$args);
- $msgs = \@TestAdapters::STRUCTURED_LOG;
- is @$msgs, 1, "$desc expected number of structured messages from $type logger";
- is $msgs->[0]->{category}, 'main',
- "$desc expected category from $type logger";
- is $msgs->[0]->{level}, 'info',
- "$desc expected level from $type logger";
- $msg = $msgs->[0]->{messages}->[0]; # "messages" for text
- is $msg, $expected,
- "$desc expected message from $type logger";
-
- $type = 'stack trace';
+ foo("bar", "baz");
- @TestAdapters::STRUCTURED_LOG = ();
- $log->$method(@$args);
- $msgs = \@TestAdapters::STRUCTURED_LOG;
- is @$msgs, 1, "$desc expected number of structured messages from $type logger";
- is $msgs->[0]->{category}, 'main',
- "$desc expected category from $type logger";
- is $msgs->[0]->{level}, 'info',
- "$desc expected level from $type logger";
- $msg = $msgs->[0]->{data}->[0]; # "data" for non-text
- is ref $msg, 'Log::Any::MessageWithStackTrace',
- "$desc expected message object from $type logger";
- is "$msg", $expected,
- "$desc expected stringified message from $type logger";
- my $trace = $msg->stack_trace;
- is ref $trace, 'Devel::StackTrace',
- "$desc expected stack_trace object from $type logger";
- is $trace->frame_count, 2,
- "$desc stack_trace object has expected number of frames from $type logger";
- # first frame should be the call to "info" inside this sub (19 lines up),
- # second frame should be the call to this sub from main
- is $trace->frame(0)->line, __LINE__ - 19,
- "$desc stack_trace object has expected first frame from $type logger";
- is $trace->frame(1)->subroutine, 'main::check_test_cases',
- "$desc stack_trace object has expected second frame from $type logger";
- if (!$is_formatted && @$args > 1) {
- my $more_data = $msgs->[0]->{data}->[1];
- is_deeply $more_data, $args->[1],
- "expected structured data from $type logger";
+ my $logged = \@TestAdapters::STRUCTURED_LOG;
+
+ my $long_desc = "$type $desc";
+
+ is @$logged, 1,
+ "$long_desc - got expected number of log messages";
+ my $msg = $logged->[0];
+ is $msg->{category}, 'main',
+ "$long_desc - got expected category";
+ is $msg->{level}, 'info',
+ "$long_desc - got expected level";
+
+ my $expected = $expected_by_type->{$type};
+
+ if (ref $expected) {
+ my $messages = $msg->{messages};
+ is $messages, undef,
+ "$long_desc - got expected number of structured messages";
+ my $data = $msg->{data};
+ if (@$extra_args == 0) {
+ is @$data, 1,
+ "$long_desc - got expected number of structured data";
+ }
+ elsif (@$extra_args == 1 && ref $extra_args->[0] eq 'HASH') {
+ is @$data, 2,
+ "$long_desc - got expected number of structured data";
+ is_deeply $data->[1], $extra_args->[0],
+ "$long_desc - got expected extra structured data";
+ }
+ else {
+ is $data, undef,
+ "$long_desc - got expected number of structured data";
+ }
+ my $thing = $data->[0];
+ my $blessed = blessed $thing;
+
+ my $expected_value = $expected->[0];
+ my $expected_type = $expected->[1];
+
+ if ($blessed || ! ref $expected_value) {
+
+ if (ref $expected_value eq 'Regexp') {
+ like "$thing", $expected_value,
+ "$long_desc - message stringifies correctly";
+ }
+ else {
+ is "$thing", $expected_value,
+ "$long_desc - message stringifies correctly";
+ }
+ }
+ is ref $thing, $expected_type,
+ "$long_desc - expected type of structured data got logged";
+
+ my (@frames, $stack_trace);
+ if ($blessed) {
+ @frames = $thing->can("frames") ? $thing->frames : ();
+ unless (@frames) {
+ $stack_trace = $thing->can("stack_trace")
+ ? $thing->stack_trace
+ : $thing->can("trace")
+ ? $thing->trace : undef;
+ @frames = $stack_trace->frames if $stack_trace;
+ }
+ }
+ if (@frames) {
+
+ # Mojo::Exception returns a listref istead of a list:
+ @frames = @{$frames[0]} if @frames == 1 &&
+ ref $frames[0] eq 'ARRAY';
+
+ my $frame = $frames[-1];
+ my $sub = $expected_type eq "Mojo::Exception"
+ ? $frame->[3] : $frame->subroutine;
+ is $sub, "main::foo",
+ "$long_desc - first frame has correct sub";
+ unless ($expected_type eq "Mojo::Exception") {
+ if ($type eq "proxy log") {
+ is_deeply [$frame->args], [],
+ "$long_desc - first frame has expected args";
+ }
+ elsif ($type eq "proxy log show args") {
+ is_deeply [$frame->args], ["bar","baz"],
+ "$long_desc - first frame has expected args";
+ }
+ }
+ $frame = $frames[-2];
+ $sub = $expected_type eq "Mojo::Exception"
+ ? $frame->[3] : $frame->subroutine;
+ is $sub, "main::bar",
+ "$long_desc - second frame has correct sub";
+ unless ($expected_type eq "Mojo::Exception") {
+ if ($type eq "proxy log") {
+ is_deeply [$frame->args], [],
+ "$long_desc - second frame has expected args";
+ }
+ elsif ($type eq "proxy log show args") {
+ is_deeply [$frame->args], ["quux"],
+ "$long_desc - second frame has expected args";
+ }
+ }
+ }
+ }
+ else {
+ my $messages = $msg->{messages};
+ my @expected = ($expected);
+ push @expected, $extra_args->[0] if $extra_args->[0] &&
+ ref $extra_args->[0] ne 'HASH';
+ push @expected, $extra_args->[1] if $extra_args->[1];
+ is @$messages, @expected,
+ "$long_desc - got expected number of structured messages";
+ is_deeply $messages, \@expected,
+ "$long_desc - expected structured message got logged";
+ my $data = $msg->{data};
+ if (ref $extra_args->[0] eq 'HASH') {
+ is @$data, 1,
+ "$long_desc - got expected number of structured data";
+ is_deeply $data->[0], $extra_args->[0],
+ "$long_desc - got expected structured data";
+ }
+ else {
+ is $data, undef,
+ "$long_desc - got expected number of structured data";
+ }
}
}
}
-check_test_cases();
-