|
25 | 25 | COMPONENT_INSTANCE_INDEX = 0
|
26 | 26 |
|
27 | 27 | _framework_support_map = {}
|
28 |
| -_request_logger = None |
29 | 28 | _current_framework = None
|
30 | 29 | _logger = get_library_logger(__name__)
|
31 | 30 | _request_util = None
|
@@ -158,26 +157,31 @@ def init_request_instrument(app=None):
|
158 | 157 |
|
159 | 158 | :param app: current web application instance
|
160 | 159 | """
|
| 160 | + |
161 | 161 | if _current_framework is None or _current_framework == '-':
|
162 | 162 | raise RuntimeError("please init the logging first, call init(framework_name) first")
|
163 | 163 |
|
164 | 164 | configurator = _current_framework['app_request_instrumentation_configurator']()
|
165 | 165 | configurator.config(app)
|
166 |
| - request_logger = configurator.request_logger |
167 |
| - handlers = request_logger.handlers |
| 166 | + |
| 167 | + handlers = configurator.request_logger.handlers |
168 | 168 | for handler in handlers:
|
169 | 169 | handler.setFormatter(JSONRequestLogFormatter())
|
170 | 170 |
|
171 | 171 |
|
172 | 172 | def get_request_logger():
|
173 | 173 | global _request_logger
|
| 174 | + |
174 | 175 | if _current_framework is None or _current_framework == '-':
|
175 |
| - raise RuntimeError("please init the logging first, call init(framework_name) first") |
| 176 | + raise RuntimeError( |
| 177 | + "request_logger is only available if json_logging is inited with a web app, " |
| 178 | + "call init_<framework_name>() to do that") |
176 | 179 |
|
177 |
| - if _request_logger is None: |
178 |
| - raise RuntimeError("please init request instrument first, call init_request_instrument(app) first") |
| 180 | + instance = _current_framework['app_request_instrumentation_configurator']._instance |
| 181 | + if instance is None: |
| 182 | + raise RuntimeError("please init request instrument first, call init_request_instrument(app) to do that") |
179 | 183 |
|
180 |
| - return _request_logger |
| 184 | + return instance.request_logger |
181 | 185 |
|
182 | 186 |
|
183 | 187 | class RequestInfo(dict):
|
|
0 commit comments