@@ -378,11 +378,8 @@ def test_stack_info(self):
378378 logger = logging .getLogger ('test_formatter' )
379379 self ._configure_logger (
380380 logger ,
381- fmt = dictionary ([
382- ('levelname' , 'levelname' ),
383- ('name' , 'name' ),
384- ('message' , 'message' ),
385- ])
381+ fmt = dictionary ([('levelname' , 'levelname' ), ('name' , 'name' ),
382+ ('message' , 'message' ), ('stack_info' , 'stack_info' )])
386383 )
387384 logger .info ('Message with stack info' , stack_info = True )
388385 message = json .loads (ctx .output [0 ], object_pairs_hook = dictionary )
@@ -825,3 +822,41 @@ def test_exc_info_without_configuration(self):
825822 ("message" , "Error occurred" ), # no exc_text because it wasn't configured
826823 ])
827824 )
825+
826+ def test_stack_info_without_configuration (self ):
827+ """
828+ Test that the stack_info doesn't appear in the record when it's
829+ not configured, even though the log call records it
830+ """
831+ with self .assertLogs ('test_formatter' , level = logging .DEBUG ) as ctx :
832+ logger = logging .getLogger ('test_formatter' )
833+ self ._configure_logger (
834+ logger ,
835+ fmt = dictionary ([
836+ ('level' , 'levelname' ),
837+ ('request' , ['request.path' , 'request.method' ]),
838+ ('message' , 'message' ),
839+ ]),
840+ remove_empty = True ,
841+ ignore_missing = True
842+ )
843+
844+ logger .info (
845+ "Stack isn't wished for here" ,
846+ exc_info = sys .exc_info (),
847+ extra = {'request' : {
848+ 'path' : '/my/path' , 'method' : 'GET' , 'scheme' : 'https'
849+ }},
850+ # record the stack_info
851+ stack_info = True
852+ )
853+
854+ self .assertDictEqual (
855+ json .loads (ctx .output [0 ], object_pairs_hook = dictionary ),
856+ dictionary ([
857+ ("level" , "INFO" ),
858+ ("request" , ["/my/path" , "GET" ]),
859+ ("message" ,
860+ "Stack isn't wished for here" ), # no stack_info because it wasn't configured
861+ ])
862+ )
0 commit comments