@@ -140,23 +140,27 @@ defmodule Logger.TranslatorTest do
140
140
end
141
141
142
142
setup_all do
143
- sasl_reports? = Application . get_env ( :logger , :handle_sasl_reports , false )
144
- Application . put_env ( :logger , :handle_sasl_reports , true )
143
+ config = Application . get_all_env ( :logger )
145
144
146
- # Shutdown the application
147
- Logger.App . stop ( )
145
+ config
146
+ |> Keyword . put ( :handle_sasl_reports , true )
147
+ |> put_logger_config ( )
148
148
149
- # And start it without warnings
150
- Application . put_env ( :logger , :level , :error )
151
- Application . start ( :logger )
152
- Application . delete_env ( :logger , :level )
153
- Logger . configure ( level: :debug )
149
+ on_exit ( fn -> restore_logger_config ( config ) end )
150
+ end
154
151
155
- on_exit ( fn ->
156
- Application . put_env ( :logger , :handle_sasl_reports , sasl_reports? )
157
- Logger.App . stop ( )
158
- Application . start ( :logger )
159
- end )
152
+ setup context do
153
+ test_overrides = Map . get ( context , :logger_config , [ ] )
154
+ existing_config = Application . get_all_env ( :logger )
155
+
156
+ case Keyword . merge ( existing_config , test_overrides ) do
157
+ ^ existing_config ->
158
+ :ok
159
+
160
+ new_config ->
161
+ put_logger_config ( new_config )
162
+ on_exit ( fn -> restore_logger_config ( existing_config ) end )
163
+ end
160
164
end
161
165
162
166
setup do
@@ -1259,6 +1263,13 @@ defmodule Logger.TranslatorTest do
1259
1263
:code . delete ( WeirdFunctionNamesGenServer )
1260
1264
end
1261
1265
1266
+ @ tag logger_config: [ handle_otp_reports: false ]
1267
+ test "drops events if otp report handling is switched off" do
1268
+ { :ok , pid } = GenServer . start ( MyGenServer , :ok )
1269
+ catch_exit ( GenServer . call ( pid , :error ) )
1270
+ refute_receive { :event , _ , _ } , 200
1271
+ end
1272
+
1262
1273
def task ( parent , fun \\ fn -> raise "oops" end ) do
1263
1274
mon = Process . monitor ( parent )
1264
1275
Process . unlink ( parent )
@@ -1312,4 +1323,25 @@ defmodule Logger.TranslatorTest do
1312
1323
defp worker ( name , args , opts \\ [ ] ) do
1313
1324
Enum . into ( opts , % { id: name , start: { name , opts [ :function ] || :start_link , args } } )
1314
1325
end
1326
+
1327
+ defp put_logger_config ( new_config ) do
1328
+ Application . put_all_env ( logger: new_config )
1329
+
1330
+ Logger.App . stop ( )
1331
+
1332
+ # Shutdown the application
1333
+ Logger.App . stop ( )
1334
+
1335
+ # And start it without warnings
1336
+ Application . put_env ( :logger , :level , :error )
1337
+ Application . start ( :logger )
1338
+ Application . delete_env ( :logger , :level )
1339
+ Logger . configure ( level: :debug )
1340
+ end
1341
+
1342
+ defp restore_logger_config ( config ) do
1343
+ Application . put_all_env ( logger: config )
1344
+ Logger.App . stop ( )
1345
+ Application . start ( :logger )
1346
+ end
1315
1347
end
0 commit comments