File: 02ignore.t

package info (click to toggle)
libtest-log4perl-perl 0.1001-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 128 kB
  • sloc: perl: 562; makefile: 2
file content (254 lines) | stat: -rw-r--r-- 6,455 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
#!/usr/bin/perl

use strict;
use warnings;

use Log::Log4perl;
# do some setup here...honest guv

use Test::More tests => 2;
use Test::Builder::Tester;
use Test::Log4perl;
use Test::Exception;

my $logger   = Log::Log4perl->get_logger("Foo");
my $tlogger  = Test::Log4perl->get_logger("Foo");
my $t2logger = Test::Log4perl->get_logger("Bar");

########################################################

# test that we ignore some priorities

test_out("ok 1 - Log4perl test");

Test::Log4perl->start(
  ignore_priority => "warn",
);

$tlogger->error("my hair is on fire!");
$logger->debug("ignore me");
$logger->info("ignore me too");
$logger->warn("ignore me as well");
$logger->error("my hair is on fire!");

Test::Log4perl->end();

# but they go back at the start of the next thing

test_out("not ok 2 - Log4perl test");
test_fail(+15);
test_diag("1st message logged wasn't what we expected:");
test_diag(" priority was 'debug'");
test_diag("          not 'error'");
test_diag("  message was 'ignore me'");
test_diag("          not 'my hair is on fire!'");
test_diag(" (Offending log call from line ".(__LINE__+4)." in ".filename().")");
Test::Log4perl->start();

$tlogger->error("my hair is on fire!");
$logger->debug("ignore me");
$logger->info("ignore me too");
$logger->warn("ignore me as well");
$logger->error("my hair is on fire!");

Test::Log4perl->end();

# test that we can ignore everything

test_out("ok 3 - Log4perl test");

Test::Log4perl->start(
  ignore_priority => "everything",
);

$logger->debug("ignore me");
$logger->info("ignore me too");
$logger->warn("ignore me as well");
$logger->error("ignore with pleasure");
$logger->fatal("ignore this finally");

Test::Log4perl->end();

# but they go back at the start of the next thing

test_out("not ok 4 - Log4perl test");
test_fail(+15);
test_diag("1st message logged wasn't what we expected:");
test_diag(" priority was 'debug'");
test_diag("          not 'error'");
test_diag("  message was 'ignore me'");
test_diag("          not 'my hair is on fire!'");
test_diag(" (Offending log call from line ".(__LINE__+4)." in ".filename().")");
Test::Log4perl->start();

$tlogger->error("my hair is on fire!");
$logger->debug("ignore me");
$logger->info("ignore me too");
$logger->warn("ignore me as well");
$logger->error("my hair is on fire!");

Test::Log4perl->end();

test_test("ignoring priority");

########################################################

# test that we ignore some priorities forever

test_out("ok 1 - Log4perl test");

Test::Log4perl->start(
  # this should be overriden
  ignore_priority => "error",
);

Test::Log4perl->ignore_priority("warn");

$tlogger->error("my hair is on fire!");
$logger->debug("ignore me");
$logger->info("ignore me too");
$logger->warn("ignore me as well");
$logger->error("my hair is on fire!");

Test::Log4perl->end();

# and they don't go back, the ignore priority
# should still be set

test_out("ok 2 - Log4perl test");

Test::Log4perl->start();

$tlogger->error("my hair is on fire!");
$logger->debug("ignore me");
$logger->info("ignore me too");
$logger->warn("ignore me as well");
$logger->error("my hair is on fire!");

Test::Log4perl->end();

# though we can turn them off with ignore nothing

Test::Log4perl->start();

Test::Log4perl->ignore_priority("nothing");

test_out("not ok 3 - Log4perl test");
test_fail(+15);
test_diag("1st message logged wasn't what we expected:");
test_diag(" priority was 'debug'");
test_diag("          not 'error'");
test_diag("  message was 'ignore me'");
test_diag("          not 'my hair is on fire!'");
test_diag(" (Offending log call from line ".(__LINE__+4)." in ".filename().")");
Test::Log4perl->start();

$tlogger->error("my hair is on fire!");
$logger->debug("ignore me");
$logger->info("ignore me too");
$logger->warn("ignore me as well");
$logger->error("my hair is on fire!");

Test::Log4perl->end();

# and that's still set next time

Test::Log4perl->start();

test_out("not ok 4 - Log4perl test");
test_fail(+16);
test_diag("1st message logged wasn't what we expected:");
test_diag(" priority was 'debug'");
test_diag("          not 'error'");
test_diag("  message was 'ignore me'");
test_diag("          not 'my hair is on fire!'");
test_diag(" (Offending log call from line ".(__LINE__+5)." in ".filename().")");

Test::Log4perl->start();

$tlogger->error("my hair is on fire!");
$logger->debug("ignore me");
$logger->info("ignore me too");
$logger->warn("ignore me as well");
$logger->error("my hair is on fire!");

Test::Log4perl->end();

# and we can ignore everything

Test::Log4perl->start();
Test::Log4perl->ignore_priority("everything");

test_out("ok 5 - Log4perl test");

$logger->debug("ignore me");
$logger->info("ignore me too");
$logger->warn("ignore me as well");
$logger->error("ignore with pleasure");
$logger->fatal("ignore this finally");

Test::Log4perl->end();

# and things are still ignored

Test::Log4perl->start();
Test::Log4perl->ignore_priority("everything");

test_out("ok 6 - Log4perl test");

$logger->debug("ignore me");
$logger->info("ignore me too");
$logger->warn("ignore me as well");
$logger->error("ignore with pleasure");
$logger->fatal("ignore this finally");

Test::Log4perl->end();

# and we can ignore nothing

Test::Log4perl->start();
Test::Log4perl->ignore_priority("nothing");

test_out("ok 7 - Log4perl test");

$tlogger->debug("don't ignore me");
$tlogger->info("don't ignore me too");
$tlogger->warn("don't ignore me as well");
$tlogger->error("don't ignore with pleasure");
$tlogger->fatal("don't ignore this finally");
$logger->debug("don't ignore me");
$logger->info("don't ignore me too");
$logger->warn("don't ignore me as well");
$logger->error("don't ignore with pleasure");
$logger->fatal("don't ignore this finally");

Test::Log4perl->end();

# and that remains set too

Test::Log4perl->start();

test_out("ok 8 - Log4perl test");

$tlogger->debug("don't ignore me");
$tlogger->info("don't ignore me too");
$tlogger->warn("don't ignore me as well");
$tlogger->error("don't ignore with pleasure");
$tlogger->fatal("don't ignore this finally");
$logger->debug("don't ignore me");
$logger->info("don't ignore me too");
$logger->warn("don't ignore me as well");
$logger->error("don't ignore with pleasure");
$logger->fatal("don't ignore this finally");

Test::Log4perl->end();

test_test("ignoring priority forever");

##################################
##################################

sub filename
{
  return (caller)[1];
}