4
4
import logging
5
5
import re
6
6
7
- from .context import SATOSABadContextError
8
- from .exception import SATOSAError
7
+ from satosa .context import SATOSABadContextError
8
+ from satosa .exception import SATOSAError
9
+
10
+ import satosa .logging_util as lu
11
+
9
12
10
13
logger = logging .getLogger (__name__ )
11
14
@@ -80,7 +83,7 @@ def backend_routing(self, context):
80
83
:return: backend
81
84
"""
82
85
msg = "Routing to backend: {backend}" .format (backend = context .target_backend )
83
- logline = "[{id}] {message}" . format (id = context .state . get ( "SESSION_ID" ), message = msg )
86
+ logline = lu . LOG_FMT . format (id = lu . get_session_id ( context .state ), message = msg )
84
87
logger .debug (logline )
85
88
backend = self .backends [context .target_backend ]["instance" ]
86
89
context .state [STATE_KEY ] = context .target_frontend
@@ -99,7 +102,7 @@ def frontend_routing(self, context):
99
102
100
103
target_frontend = context .state [STATE_KEY ]
101
104
msg = "Routing to frontend: {frontend}" .format (frontend = target_frontend )
102
- logline = "[{id}] {message}" . format (id = context .state . get ( "SESSION_ID" ), message = msg )
105
+ logline = lu . LOG_FMT . format (id = lu . get_session_id ( context .state ), message = msg )
103
106
logger .debug (logline )
104
107
context .target_frontend = target_frontend
105
108
frontend = self .frontends [context .target_frontend ]["instance" ]
@@ -110,10 +113,11 @@ def _find_registered_endpoint_for_module(self, module, context):
110
113
match = re .search (regex , context .path )
111
114
if match is not None :
112
115
msg = "Found registered endpoint: module name:'{name}', endpoint: {endpoint}" .format (
113
- name = module ["instance" ].name ,
114
- endpoint = context .path )
115
- logline = "[{id}] {message}" .format (
116
- id = context .state .get ("SESSION_ID" ), message = msg )
116
+ name = module ["instance" ].name , endpoint = context .path
117
+ )
118
+ logline = lu .LOG_FMT .format (
119
+ id = lu .get_session_id (context .state ), message = msg
120
+ )
117
121
logger .debug (logline )
118
122
return spec
119
123
@@ -142,13 +146,14 @@ def endpoint_routing(self, context):
142
146
"""
143
147
if context .path is None :
144
148
msg = "Context did not contain a path!"
145
- logline = "[{id}] {message}" .format (
146
- id = context .state .get ("SESSION_ID" ), message = msg )
149
+ logline = lu .LOG_FMT .format (
150
+ id = lu .get_session_id (context .state ), message = msg
151
+ )
147
152
logger .debug (logline )
148
153
raise SATOSABadContextError ("Context did not contain any path" )
149
154
150
155
msg = "Routing path: {path}" .format (path = context .path )
151
- logline = "[{id}] {message}" . format (id = context .state . get ( "SESSION_ID" ), message = msg )
156
+ logline = lu . LOG_FMT . format (id = lu . get_session_id ( context .state ), message = msg )
152
157
logger .debug (logline )
153
158
path_split = context .path .split ("/" )
154
159
backend = path_split [0 ]
@@ -157,7 +162,9 @@ def endpoint_routing(self, context):
157
162
context .target_backend = backend
158
163
else :
159
164
msg = "Unknown backend {}" .format (backend )
160
- logline = "[{id} {message}" .format (id = context .state .get ("SESSION_ID" ), message = msg )
165
+ logline = lu .LOG_FMT .format (
166
+ id = lu .get_session_id (context .state ), message = msg
167
+ )
161
168
logger .debug (logline )
162
169
163
170
try :
0 commit comments