Skip to content

Commit cf3e5ac

Browse files
authored
Merge pull request #37 from thangbn/thangbn-patch-1
fix #36
2 parents 4cfe5f4 + ca8daa7 commit cf3e5ac

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

json_logging/__init__.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
COMPONENT_INSTANCE_INDEX = 0
2626

2727
_framework_support_map = {}
28-
_request_logger = None
2928
_current_framework = None
3029
_logger = get_library_logger(__name__)
3130
_request_util = None
@@ -158,26 +157,31 @@ def init_request_instrument(app=None):
158157
159158
:param app: current web application instance
160159
"""
160+
161161
if _current_framework is None or _current_framework == '-':
162162
raise RuntimeError("please init the logging first, call init(framework_name) first")
163163

164164
configurator = _current_framework['app_request_instrumentation_configurator']()
165165
configurator.config(app)
166-
request_logger = configurator.request_logger
167-
handlers = request_logger.handlers
166+
167+
handlers = configurator.request_logger.handlers
168168
for handler in handlers:
169169
handler.setFormatter(JSONRequestLogFormatter())
170170

171171

172172
def get_request_logger():
173173
global _request_logger
174+
174175
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")
176179

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")
179183

180-
return _request_logger
184+
return instance.request_logger
181185

182186

183187
class RequestInfo(dict):

0 commit comments

Comments
 (0)