Skip to content

Commit 7a5e9a2

Browse files
authored
Merge pull request #3 from oposs/support-trace
add support for trace log level
2 parents c933cc7 + 264a5a3 commit 7a5e9a2

File tree

5 files changed

+71
-7
lines changed

5 files changed

+71
-7
lines changed

CHANGES

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
0.2.1 2021-09-06 08:36:03 +0200 Tobias Oetiker <[email protected]>
2+
3+
- fix documentation
4+
5+
0.2.0 2021-09-06 08:32:36 +0200 Tobias Oetiker <[email protected]>
6+
7+
- support new trace log level
8+
19
0.1.0 2020-09-03 11:27:29 +0200 Tobias Oetiker <[email protected]>
210

311
- initial release

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Points to an array with all the log messages issued since the last request.
3131

3232
# METHODS
3333

34-
The role [Test::Mojo::Role::Log](https://metacpan.org/pod/Test%3A%3AMojo%3A%3ARole%3A%3ALog) adds following new methods to [Test::Mojo](https://metacpan.org/pod/Test%3A%3AMojo) ones.
34+
The role [Test::Mojo::Role::Log](https://metacpan.org/pod/Test%3A%3AMojo%3A%3ARole%3A%3ALog) adds the following new methods to [Test::Mojo](https://metacpan.org/pod/Test%3A%3AMojo) ones.
3535

3636
## log\_like($rx,$desc)
3737

@@ -44,6 +44,10 @@ The role [Test::Mojo::Role::Log](https://metacpan.org/pod/Test%3A%3AMojo%3A%3ARo
4444
Check if the given log message has been issued. All the log messages issued since the start of the current request will get checked.
4545
If $logLevel is set to undef the logLevel does not get checked.
4646

47+
## log\_trace\_like($rx,$desc) (if mojo supports it)
48+
49+
Find a trace level log message matching the given $rx.
50+
4751
## log\_debug\_like($rx,$desc)
4852

4953
Find a debug level log message matching the given $rx.
@@ -67,7 +71,8 @@ Find a fatal level log message matching the given $rx.
6771
## \*\_unlike
6872

6973
For each of the methods above there is ac coresponding
70-
&#x3d;head1 AUTHOR
74+
75+
# AUTHOR
7176

7277
Tobias Oetiker <[email protected]>
7378

lib/Test/Mojo/Role/Log.pm

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package Test::Mojo::Role::Log;
22
use Mojo::Base -role, -signatures;
3-
our $VERSION = '0.1.0';
3+
our $VERSION = '0.2.1';
44

55
around 'new' => sub {
66
my $orig = shift;
@@ -10,9 +10,13 @@ around 'new' => sub {
1010
$log->unsubscribe(
1111
message => $log->subscribers('message')->[0]
1212
);
13-
$log->level('debug');
13+
if ($log->can('trace')){
14+
$log->level('trace');
15+
}
16+
else {
17+
$log->level('debug');
18+
}
1419
}
15-
1620
$log->on(message => sub {
1721
my $log = shift;
1822
push @{$self->logCache}, \@_;
@@ -55,33 +59,50 @@ sub log_unlike ($self,$rx,$desc=undef) {
5559
return $self->_log_test($rx,undef,'unlike',$desc);
5660
}
5761

62+
sub log_trace_like ($self,$rx,$desc=undef) {
63+
return shift->_log_test($rx,'trace','like',$desc);
64+
}
65+
5866
sub log_debug_like ($self,$rx,$desc=undef) {
5967
return shift->_log_test($rx,'debug','like',$desc);
6068
}
69+
6170
sub log_info_like ($self,$rx,$desc=undef) {
6271
return shift->_log_test($rx,'info','like',$desc);
6372
}
73+
6474
sub log_warn_like ($self,$rx,$desc=undef) {
6575
return shift->_log_test($rx,'warn','like',$desc);
6676
}
77+
6778
sub log_error_like ($self,$rx,$desc=undef) {
6879
return shift->_log_test($rx,'error','like',$desc);
6980
}
81+
7082
sub log_fatal_like ($self,$rx,$desc=undef) {
7183
return shift->_log_test($rx,'fatal','like',$desc);
7284
}
85+
86+
sub log_trace_unlike ($self,$rx,$desc=undef) {
87+
return shift->_log_test($rx,'trace','unlike',$desc);
88+
}
89+
7390
sub log_debug_unlike ($self,$rx,$desc=undef) {
7491
return shift->_log_test($rx,'debug','unlike',$desc);
7592
}
93+
7694
sub log_info_unlike ($self,$rx,$desc=undef) {
7795
return shift->_log_test($rx,'info','unlike',$desc);
7896
}
97+
7998
sub log_warn_unlike ($self,$rx,$desc=undef) {
8099
return shift->_log_test($rx,'warn','unlike',$desc);
81100
}
101+
82102
sub log_error_unlike ($self,$rx,$desc=undef) {
83103
return shift->_log_test($rx,'error','unlike',$desc);
84104
}
105+
85106
sub log_fatal_unlike ($self,$rx,$desc=undef) {
86107
return shift->_log_test($rx,'fatal','unlike',$desc);
87108
}
@@ -121,7 +142,7 @@ Points to an array with all the log messages issued since the last request.
121142
122143
=head1 METHODS
123144
124-
The role L<Test::Mojo::Role::Log> adds following new methods to L<Test::Mojo> ones.
145+
The role L<Test::Mojo::Role::Log> adds the following new methods to L<Test::Mojo> ones.
125146
126147
=head2 log_like($rx,$desc)
127148
@@ -131,6 +152,10 @@ The role L<Test::Mojo::Role::Log> adds following new methods to L<Test::Mojo> on
131152
Check if the given log message has been issued. All the log messages issued since the start of the current request will get checked.
132153
If $logLevel is set to undef the logLevel does not get checked.
133154
155+
=head2 log_trace_like($rx,$desc) (if mojo supports it)
156+
157+
Find a trace level log message matching the given $rx.
158+
134159
=head2 log_debug_like($rx,$desc)
135160
136161
Find a debug level log message matching the given $rx.
@@ -154,6 +179,7 @@ Find a fatal level log message matching the given $rx.
154179
=head2 *_unlike
155180
156181
For each of the methods above there is ac coresponding
182+
157183
=head1 AUTHOR
158184
159185
Tobias Oetiker E<lt>[email protected]E<gt>

t/basic.t

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,28 @@ use Test::More;
1010
# Start a Mojolicious app named "Celestial"
1111
my $t = Test::Mojo->with_roles('+Log')->new(curfile->sibling('hello.pl'));
1212

13+
if ($t->app->log->can('trace')){
14+
$t->get_ok('/gugus')
15+
->log_like(qr{GET "/gugus"})
16+
->log_trace_like(qr{GET "/gugus"})
17+
->log_debug_unlike(qr{GET "/gugus"})
18+
->log_like(qr{200 OK.+s.+/s})
19+
->log_unlike(qr{aargh})
20+
->log_like(qr{gugus})
21+
->log_trace_like(qr{trace})
22+
->log_debug_like(qr{debug})
23+
->log_info_like(qr{info})
24+
->log_warn_like(qr{warn})
25+
->log_error_like(qr{error})
26+
->log_fatal_like(qr{fatal})
27+
->log_trace_unlike(qr{xtrace})
28+
->log_debug_unlike(qr{xdebug})
29+
->log_info_unlike(qr{xinfo})
30+
->log_warn_unlike(qr{xwarn})
31+
->log_error_unlike(qr{xerror})
32+
->log_fatal_unlike(qr{xfatal});
33+
}
34+
else {
1335
$t->get_ok('/gugus')
1436
->log_like(qr{GET "/gugus"})
1537
->log_debug_like(qr{GET "/gugus"})
@@ -27,5 +49,5 @@ $t->get_ok('/gugus')
2749
->log_warn_unlike(qr{xwarn})
2850
->log_error_unlike(qr{xerror})
2951
->log_fatal_unlike(qr{xfatal});
30-
52+
}
3153
done_testing();

t/hello.pl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
# Route with placeholder
88
get '/:foo' => sub ($c) {
9+
if ($c->log->can('trace')){
10+
$c->log->trace("trace");
11+
}
912
$c->log->debug("debug");
1013
$c->log->info("info");
1114
$c->log->warn("warn");

0 commit comments

Comments
 (0)