@@ -32,7 +32,7 @@ def in_container_env(example)
32
32
33
33
subject { described_class . create_logger ( log_file ) }
34
34
35
- let ( :container_log ) { subject . try ( :wrapped_logger ) }
35
+ let ( :container_log ) { subject . try ( :broadcasts ) . try ( :last ) }
36
36
37
37
before do
38
38
# Hide the container logger output to STDOUT
@@ -65,15 +65,21 @@ def in_container_env(example)
65
65
66
66
it "#logdev" do
67
67
if container_log
68
- expect ( subject . logdev ) . to be_nil
68
+ expect ( subject . broadcasts . first . logdev ) . to be_nil
69
+ expect ( container_log . logdev ) . to be_a Logger ::LogDevice
69
70
else
70
71
expect ( subject . logdev ) . to be_a Logger ::LogDevice
71
72
end
72
73
end
73
74
74
75
describe "#datetime_format" do
75
76
it "return nil" do
76
- expect ( subject . datetime_format ) . to be nil
77
+ if container_log
78
+ expect ( subject . datetime_format . first ) . to be nil
79
+ expect ( subject . datetime_format . last ) . to be nil
80
+ else
81
+ expect ( subject . datetime_format ) . to be nil
82
+ end
77
83
end
78
84
79
85
it "does not raise an error" do
@@ -91,15 +97,18 @@ def in_container_env(example)
91
97
end
92
98
93
99
it "forwards to the other loggers" do
94
- expect ( subject ) . to receive ( :add ) . with ( 1 , nil , "test message" ) . and_call_original
95
- expect ( container_log ) . to receive ( :add ) . with ( 1 , nil , "test message" ) . and_call_original if container_log
96
-
100
+ if container_log
101
+ expect ( subject . broadcasts . first ) . to receive ( :add ) . with ( 1 , nil , "test message" ) . and_call_original
102
+ expect ( subject . broadcasts . last ) . to receive ( :add ) . with ( 1 , nil , "test message" ) . and_call_original
103
+ else
104
+ expect ( subject ) . to receive ( :add ) . with ( 1 , nil , "test message" ) . and_call_original
105
+ end
97
106
subject . info ( "test message" )
98
107
end
99
108
100
109
it "only forwards the message if the severity is correct" do
101
110
if container_log
102
- expect ( subject . logdev ) . to be_nil
111
+ expect ( subject . broadcasts . first . logdev ) . to be_nil
103
112
expect ( container_log . logdev ) . not_to receive ( :write ) . with ( "test message" )
104
113
else
105
114
expect ( subject . logdev ) . not_to receive ( :write ) . with ( "test message" )
@@ -139,8 +148,12 @@ def in_container_env(example)
139
148
let ( :log_file ) { StringIO . new }
140
149
141
150
it "logs correctly" do
142
- expect ( subject ) . to receive ( :add ) . with ( 1 , nil , "test message" ) . and_call_original
143
- expect ( container_log ) . to receive ( :add ) . with ( 1 , nil , "test message" ) . and_call_original if container_log
151
+ if container_log
152
+ expect ( subject . broadcasts . first ) . to receive ( :add ) . with ( 1 , nil , "test message" ) . and_call_original
153
+ expect ( subject . broadcasts . last ) . to receive ( :add ) . with ( 1 , nil , "test message" ) . and_call_original
154
+ else
155
+ expect ( subject ) . to receive ( :add ) . with ( 1 , nil , "test message" ) . and_call_original
156
+ end
144
157
145
158
subject . info ( "test message" )
146
159
@@ -154,8 +167,12 @@ def in_container_env(example)
154
167
after { log_file . delete if log_file . exist? }
155
168
156
169
it "logs correctly" do
157
- expect ( subject ) . to receive ( :add ) . with ( 1 , nil , "test message" ) . and_call_original
158
- expect ( container_log ) . to receive ( :add ) . with ( 1 , nil , "test message" ) . and_call_original if container_log
170
+ if container_log
171
+ expect ( subject . broadcasts . first ) . to receive ( :add ) . with ( 1 , nil , "test message" ) . and_call_original
172
+ expect ( subject . broadcasts . last ) . to receive ( :add ) . with ( 1 , nil , "test message" ) . and_call_original
173
+ else
174
+ expect ( subject ) . to receive ( :add ) . with ( 1 , nil , "test message" ) . and_call_original
175
+ end
159
176
160
177
subject . info ( "test message" )
161
178
@@ -169,9 +186,12 @@ def in_container_env(example)
169
186
after { File . delete ( log_file ) if File . exist? ( log_file ) }
170
187
171
188
it "logs correctly" do
172
- expect ( subject ) . to receive ( :add ) . with ( 1 , nil , "test message" ) . and_call_original
173
- expect ( container_log ) . to receive ( :add ) . with ( 1 , nil , "test message" ) . and_call_original if container_log
174
-
189
+ if container_log
190
+ expect ( subject . broadcasts . first ) . to receive ( :add ) . with ( 1 , nil , "test message" ) . and_call_original
191
+ expect ( subject . broadcasts . last ) . to receive ( :add ) . with ( 1 , nil , "test message" ) . and_call_original
192
+ else
193
+ expect ( subject ) . to receive ( :add ) . with ( 1 , nil , "test message" ) . and_call_original
194
+ end
175
195
subject . info ( "test message" )
176
196
177
197
expect ( File . read ( log_file ) ) . to include ( "test message" ) unless container_log
@@ -212,12 +232,15 @@ def in_container_env(example)
212
232
213
233
it "will honor the log level in the container logger" do
214
234
log = described_class . create_logger ( log_file_name )
215
- container_log = log . wrapped_logger
235
+ container_log = log . broadcasts . last
216
236
217
237
described_class . apply_config_value ( { :level_foo => :error } , log , :level_foo )
218
-
219
238
expect ( log . level ) . to eq ( Logger ::ERROR )
220
239
expect ( container_log . level ) . to eq ( Logger ::ERROR )
240
+
241
+ described_class . apply_config_value ( { :level_foo => :debug } , log , :level_foo )
242
+ expect ( log . level ) . to eq ( Logger ::DEBUG )
243
+ expect ( container_log . level ) . to eq ( Logger ::DEBUG )
221
244
end
222
245
end
223
246
end
0 commit comments