@@ -189,6 +189,11 @@ def message_hello(message, say):
189189 self ._verification_token : Optional [str ] = verification_token or os .environ .get (
190190 "SLACK_VERIFICATION_TOKEN" , None
191191 )
192+ # If a logger is explicitly passed when initializing, the logger works as the base logger.
193+ # The base logger's logging settings will be propagated to all the loggers created by bolt-python.
194+ self ._base_logger = logger
195+ # The framework logger is supposed to be used for the internal logging.
196+ # Also, it's accessible via `app.logger` as the app's singleton logger.
192197 self ._framework_logger = logger or get_bolt_logger (App )
193198 self ._raise_error_for_unhandled_request = raise_error_for_unhandled_request
194199
@@ -356,10 +361,15 @@ def _init_middleware_list(
356361 return
357362 if ssl_check_enabled is True :
358363 self ._middleware_list .append (
359- SslCheck (verification_token = self ._verification_token )
364+ SslCheck (
365+ verification_token = self ._verification_token ,
366+ base_logger = self ._base_logger ,
367+ )
360368 )
361369 if request_verification_enabled is True :
362- self ._middleware_list .append (RequestVerification (self ._signing_secret ))
370+ self ._middleware_list .append (
371+ RequestVerification (self ._signing_secret , base_logger = self ._base_logger )
372+ )
363373
364374 # As authorize is required for making a Bolt app function, we don't offer the flag to disable this
365375 if self ._oauth_flow is None :
@@ -370,24 +380,33 @@ def _init_middleware_list(
370380 # This API call is for eagerly validating the token
371381 auth_test_result = self ._client .auth_test (token = self ._token )
372382 self ._middleware_list .append (
373- SingleTeamAuthorization (auth_test_result = auth_test_result )
383+ SingleTeamAuthorization (
384+ auth_test_result = auth_test_result ,
385+ base_logger = self ._base_logger ,
386+ )
374387 )
375388 except SlackApiError as err :
376389 raise BoltError (error_auth_test_failure (err .response ))
377390 elif self ._authorize is not None :
378391 self ._middleware_list .append (
379- MultiTeamsAuthorization (authorize = self ._authorize )
392+ MultiTeamsAuthorization (
393+ authorize = self ._authorize , base_logger = self ._base_logger
394+ )
380395 )
381396 else :
382397 raise BoltError (error_token_required ())
383398 else :
384399 self ._middleware_list .append (
385- MultiTeamsAuthorization (authorize = self ._authorize )
400+ MultiTeamsAuthorization (
401+ authorize = self ._authorize , base_logger = self ._base_logger
402+ )
386403 )
387404 if ignoring_self_events_enabled is True :
388- self ._middleware_list .append (IgnoringSelfEvents ())
405+ self ._middleware_list .append (
406+ IgnoringSelfEvents (base_logger = self ._base_logger )
407+ )
389408 if url_verification_enabled is True :
390- self ._middleware_list .append (UrlVerification ())
409+ self ._middleware_list .append (UrlVerification (base_logger = self . _base_logger ))
391410 self ._init_middleware_list_done = True
392411
393412 # -------------------------
@@ -616,7 +635,11 @@ def middleware_func(logger, body, next):
616635 self ._middleware_list .append (middleware )
617636 elif isinstance (middleware_or_callable , Callable ):
618637 self ._middleware_list .append (
619- CustomMiddleware (app_name = self .name , func = middleware_or_callable )
638+ CustomMiddleware (
639+ app_name = self .name ,
640+ func = middleware_or_callable ,
641+ base_logger = self ._base_logger ,
642+ )
620643 )
621644 return middleware_or_callable
622645 else :
@@ -677,9 +700,10 @@ def step(
677700 edit = edit ,
678701 save = save ,
679702 execute = execute ,
703+ base_logger = self ._base_logger ,
680704 )
681705 elif isinstance (step , WorkflowStepBuilder ):
682- step = step .build ()
706+ step = step .build (base_logger = self . _base_logger )
683707 elif not isinstance (step , WorkflowStep ):
684708 raise BoltError (f"Invalid step object ({ type (step )} )" )
685709
@@ -759,7 +783,9 @@ def ask_for_introduction(event, say):
759783
760784 def __call__ (* args , ** kwargs ):
761785 functions = self ._to_listener_functions (kwargs ) if kwargs else list (args )
762- primary_matcher = builtin_matchers .event (event )
786+ primary_matcher = builtin_matchers .event (
787+ event , base_logger = self ._base_logger
788+ )
763789 return self ._register_listener (
764790 list (functions ), primary_matcher , matchers , middleware , True
765791 )
@@ -814,7 +840,7 @@ def __call__(*args, **kwargs):
814840 ),
815841 }
816842 primary_matcher = builtin_matchers .message_event (
817- keyword = keyword , constraints = constraints
843+ keyword = keyword , constraints = constraints , base_logger = self . _base_logger
818844 )
819845 middleware .insert (0 , MessageListenerMatches (keyword ))
820846 return self ._register_listener (
@@ -859,7 +885,9 @@ def repeat_text(ack, say, command):
859885
860886 def __call__ (* args , ** kwargs ):
861887 functions = self ._to_listener_functions (kwargs ) if kwargs else list (args )
862- primary_matcher = builtin_matchers .command (command )
888+ primary_matcher = builtin_matchers .command (
889+ command , base_logger = self ._base_logger
890+ )
863891 return self ._register_listener (
864892 list (functions ), primary_matcher , matchers , middleware
865893 )
@@ -908,7 +936,9 @@ def open_modal(ack, body, client):
908936
909937 def __call__ (* args , ** kwargs ):
910938 functions = self ._to_listener_functions (kwargs ) if kwargs else list (args )
911- primary_matcher = builtin_matchers .shortcut (constraints )
939+ primary_matcher = builtin_matchers .shortcut (
940+ constraints , base_logger = self ._base_logger
941+ )
912942 return self ._register_listener (
913943 list (functions ), primary_matcher , matchers , middleware
914944 )
@@ -925,7 +955,9 @@ def global_shortcut(
925955
926956 def __call__ (* args , ** kwargs ):
927957 functions = self ._to_listener_functions (kwargs ) if kwargs else list (args )
928- primary_matcher = builtin_matchers .global_shortcut (callback_id )
958+ primary_matcher = builtin_matchers .global_shortcut (
959+ callback_id , base_logger = self ._base_logger
960+ )
929961 return self ._register_listener (
930962 list (functions ), primary_matcher , matchers , middleware
931963 )
@@ -942,7 +974,9 @@ def message_shortcut(
942974
943975 def __call__ (* args , ** kwargs ):
944976 functions = self ._to_listener_functions (kwargs ) if kwargs else list (args )
945- primary_matcher = builtin_matchers .message_shortcut (callback_id )
977+ primary_matcher = builtin_matchers .message_shortcut (
978+ callback_id , base_logger = self ._base_logger
979+ )
946980 return self ._register_listener (
947981 list (functions ), primary_matcher , matchers , middleware
948982 )
@@ -984,7 +1018,9 @@ def update_message(ack):
9841018
9851019 def __call__ (* args , ** kwargs ):
9861020 functions = self ._to_listener_functions (kwargs ) if kwargs else list (args )
987- primary_matcher = builtin_matchers .action (constraints )
1021+ primary_matcher = builtin_matchers .action (
1022+ constraints , base_logger = self ._base_logger
1023+ )
9881024 return self ._register_listener (
9891025 list (functions ), primary_matcher , matchers , middleware
9901026 )
@@ -1003,7 +1039,9 @@ def block_action(
10031039
10041040 def __call__ (* args , ** kwargs ):
10051041 functions = self ._to_listener_functions (kwargs ) if kwargs else list (args )
1006- primary_matcher = builtin_matchers .block_action (constraints )
1042+ primary_matcher = builtin_matchers .block_action (
1043+ constraints , base_logger = self ._base_logger
1044+ )
10071045 return self ._register_listener (
10081046 list (functions ), primary_matcher , matchers , middleware
10091047 )
@@ -1021,7 +1059,9 @@ def attachment_action(
10211059
10221060 def __call__ (* args , ** kwargs ):
10231061 functions = self ._to_listener_functions (kwargs ) if kwargs else list (args )
1024- primary_matcher = builtin_matchers .attachment_action (callback_id )
1062+ primary_matcher = builtin_matchers .attachment_action (
1063+ callback_id , base_logger = self ._base_logger
1064+ )
10251065 return self ._register_listener (
10261066 list (functions ), primary_matcher , matchers , middleware
10271067 )
@@ -1039,7 +1079,9 @@ def dialog_submission(
10391079
10401080 def __call__ (* args , ** kwargs ):
10411081 functions = self ._to_listener_functions (kwargs ) if kwargs else list (args )
1042- primary_matcher = builtin_matchers .dialog_submission (callback_id )
1082+ primary_matcher = builtin_matchers .dialog_submission (
1083+ callback_id , base_logger = self ._base_logger
1084+ )
10431085 return self ._register_listener (
10441086 list (functions ), primary_matcher , matchers , middleware
10451087 )
@@ -1057,7 +1099,9 @@ def dialog_cancellation(
10571099
10581100 def __call__ (* args , ** kwargs ):
10591101 functions = self ._to_listener_functions (kwargs ) if kwargs else list (args )
1060- primary_matcher = builtin_matchers .dialog_cancellation (callback_id )
1102+ primary_matcher = builtin_matchers .dialog_cancellation (
1103+ callback_id , base_logger = self ._base_logger
1104+ )
10611105 return self ._register_listener (
10621106 list (functions ), primary_matcher , matchers , middleware
10631107 )
@@ -1110,7 +1154,9 @@ def handle_submission(ack, body, client, view):
11101154
11111155 def __call__ (* args , ** kwargs ):
11121156 functions = self ._to_listener_functions (kwargs ) if kwargs else list (args )
1113- primary_matcher = builtin_matchers .view (constraints )
1157+ primary_matcher = builtin_matchers .view (
1158+ constraints , base_logger = self ._base_logger
1159+ )
11141160 return self ._register_listener (
11151161 list (functions ), primary_matcher , matchers , middleware
11161162 )
@@ -1128,7 +1174,9 @@ def view_submission(
11281174
11291175 def __call__ (* args , ** kwargs ):
11301176 functions = self ._to_listener_functions (kwargs ) if kwargs else list (args )
1131- primary_matcher = builtin_matchers .view_submission (constraints )
1177+ primary_matcher = builtin_matchers .view_submission (
1178+ constraints , base_logger = self ._base_logger
1179+ )
11321180 return self ._register_listener (
11331181 list (functions ), primary_matcher , matchers , middleware
11341182 )
@@ -1146,7 +1194,9 @@ def view_closed(
11461194
11471195 def __call__ (* args , ** kwargs ):
11481196 functions = self ._to_listener_functions (kwargs ) if kwargs else list (args )
1149- primary_matcher = builtin_matchers .view_closed (constraints )
1197+ primary_matcher = builtin_matchers .view_closed (
1198+ constraints , base_logger = self ._base_logger
1199+ )
11501200 return self ._register_listener (
11511201 list (functions ), primary_matcher , matchers , middleware
11521202 )
@@ -1199,7 +1249,9 @@ def show_menu_options(ack):
11991249
12001250 def __call__ (* args , ** kwargs ):
12011251 functions = self ._to_listener_functions (kwargs ) if kwargs else list (args )
1202- primary_matcher = builtin_matchers .options (constraints )
1252+ primary_matcher = builtin_matchers .options (
1253+ constraints , base_logger = self ._base_logger
1254+ )
12031255 return self ._register_listener (
12041256 list (functions ), primary_matcher , matchers , middleware
12051257 )
@@ -1216,7 +1268,9 @@ def block_suggestion(
12161268
12171269 def __call__ (* args , ** kwargs ):
12181270 functions = self ._to_listener_functions (kwargs ) if kwargs else list (args )
1219- primary_matcher = builtin_matchers .block_suggestion (action_id )
1271+ primary_matcher = builtin_matchers .block_suggestion (
1272+ action_id , base_logger = self ._base_logger
1273+ )
12201274 return self ._register_listener (
12211275 list (functions ), primary_matcher , matchers , middleware
12221276 )
@@ -1234,7 +1288,9 @@ def dialog_suggestion(
12341288
12351289 def __call__ (* args , ** kwargs ):
12361290 functions = self ._to_listener_functions (kwargs ) if kwargs else list (args )
1237- primary_matcher = builtin_matchers .dialog_suggestion (callback_id )
1291+ primary_matcher = builtin_matchers .dialog_suggestion (
1292+ callback_id , base_logger = self ._base_logger
1293+ )
12381294 return self ._register_listener (
12391295 list (functions ), primary_matcher , matchers , middleware
12401296 )
@@ -1265,7 +1321,9 @@ def enable_token_revocation_listeners(self) -> None:
12651321 # -------------------------
12661322
12671323 def _init_context (self , req : BoltRequest ):
1268- req .context ["logger" ] = get_bolt_app_logger (self .name )
1324+ req .context ["logger" ] = get_bolt_app_logger (
1325+ app_name = self .name , base_logger = self ._base_logger
1326+ )
12691327 req .context ["token" ] = self ._token
12701328 if self ._token is not None :
12711329 # This WebClient instance can be safely singleton
@@ -1311,15 +1369,22 @@ def _register_listener(
13111369 value_to_return = functions [0 ]
13121370
13131371 listener_matchers = [
1314- CustomListenerMatcher (app_name = self .name , func = f ) for f in (matchers or [])
1372+ CustomListenerMatcher (
1373+ app_name = self .name , func = f , base_logger = self ._base_logger
1374+ )
1375+ for f in (matchers or [])
13151376 ]
13161377 listener_matchers .insert (0 , primary_matcher )
13171378 listener_middleware = []
13181379 for m in middleware or []:
13191380 if isinstance (m , Middleware ):
13201381 listener_middleware .append (m )
13211382 elif isinstance (m , Callable ):
1322- listener_middleware .append (CustomMiddleware (app_name = self .name , func = m ))
1383+ listener_middleware .append (
1384+ CustomMiddleware (
1385+ app_name = self .name , func = m , base_logger = self ._base_logger
1386+ )
1387+ )
13231388 else :
13241389 raise ValueError (error_unexpected_listener_middleware (type (m )))
13251390
@@ -1331,6 +1396,7 @@ def _register_listener(
13311396 matchers = listener_matchers ,
13321397 middleware = listener_middleware ,
13331398 auto_acknowledgement = auto_acknowledgement ,
1399+ base_logger = self ._base_logger ,
13341400 )
13351401 )
13361402 return value_to_return
0 commit comments