Skip to content

Commit 4cfd932

Browse files
sebulibahc00kiemon5ter
authored andcommitted
Improve current logging for SATOSA (#275)
Remove satosa_logging for the routing module
1 parent 2c556ec commit 4cfd932

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

src/satosa/routing.py

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
from .context import SATOSABadContextError
88
from .exception import SATOSAError
9-
from .logging_util import satosa_logging
109

1110
logger = logging.getLogger(__name__)
1211

@@ -66,9 +65,9 @@ def __init__(self, frontends, backends, micro_services):
6665
else:
6766
self.micro_services = {}
6867

69-
logger.debug("Loaded backends with endpoints: %s" % backends)
70-
logger.debug("Loaded frontends with endpoints: %s" % frontends)
71-
logger.debug("Loaded micro services with endpoints: %s" % micro_services)
68+
logger.debug("Loaded backends with endpoints: {}".format(backends))
69+
logger.debug("Loaded frontends with endpoints: {}".format(frontends))
70+
logger.debug("Loaded micro services with endpoints: {}".format(micro_services))
7271

7372
def backend_routing(self, context):
7473
"""
@@ -80,7 +79,9 @@ def backend_routing(self, context):
8079
:param context: The request context
8180
:return: backend
8281
"""
83-
satosa_logging(logger, logging.DEBUG, "Routing to backend: %s " % context.target_backend, context.state)
82+
msg = "Routing to backend: {backend}".format(backend=context.target_backend)
83+
logline = "[{id}] {message}".format(id=context.state.get("SESSION_ID"), message=msg)
84+
logger.debug(logline)
8485
backend = self.backends[context.target_backend]["instance"]
8586
context.state[STATE_KEY] = context.target_frontend
8687
return backend
@@ -97,7 +98,9 @@ def frontend_routing(self, context):
9798
"""
9899

99100
target_frontend = context.state[STATE_KEY]
100-
satosa_logging(logger, logging.DEBUG, "Routing to frontend: %s " % target_frontend, context.state)
101+
msg = "Routing to frontend: {frontend}".format(frontend=target_frontend)
102+
logline = "[{id}] {message}".format(id=context.state.get("SESSION_ID"), message=msg)
103+
logger.debug(logline)
101104
context.target_frontend = target_frontend
102105
frontend = self.frontends[context.target_frontend]["instance"]
103106
return frontend
@@ -109,7 +112,9 @@ def _find_registered_endpoint_for_module(self, module, context):
109112
msg = "Found registered endpoint: module name:'{name}', endpoint: {endpoint}".format(
110113
name=module["instance"].name,
111114
endpoint=context.path)
112-
satosa_logging(logger, logging.DEBUG, msg, context.state)
115+
logline = "[{id}] {message}".format(
116+
id=context.state.get("SESSION_ID"), message=msg)
117+
logger.debug(logline)
113118
return spec
114119

115120
return None
@@ -136,17 +141,24 @@ def endpoint_routing(self, context):
136141
:return: registered endpoint and bound parameters
137142
"""
138143
if context.path is None:
139-
satosa_logging(logger, logging.DEBUG, "Context did not contain a path!", context.state)
144+
msg = "Context did not contain a path!"
145+
logline = "[{id}] {message}".format(
146+
id=context.state.get("SESSION_ID"), message=msg)
147+
logger.debug(logline)
140148
raise SATOSABadContextError("Context did not contain any path")
141149

142-
satosa_logging(logger, logging.DEBUG, "Routing path: %s" % context.path, context.state)
150+
msg = "Routing path: {path}".format(path=context.path)
151+
logline = "[{id}] {message}".format(id=context.state.get("SESSION_ID"), message=msg)
152+
logger.debug(logline)
143153
path_split = context.path.split("/")
144154
backend = path_split[0]
145155

146156
if backend in self.backends:
147157
context.target_backend = backend
148158
else:
149-
satosa_logging(logger, logging.DEBUG, "Unknown backend %s" % backend, context.state)
159+
msg = "Unknown backend {}".format(backend)
160+
logline = "[{id} {message}".format(id=context.state.get("SESSION_ID"), message=msg)
161+
logger.debug(logline)
150162

151163
try:
152164
name, frontend_endpoint = self._find_registered_endpoint(context, self.frontends)

0 commit comments

Comments
 (0)