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