Open idavydiak opened 2 years ago
Same behaviour here, using versions:
sanic==22.6.1
sanic-json-logging==4.1.2
I have created a workaround:
from sanic_json_logging.formatters import JSONReqFormatter
original_format = JSONReqFormatter.format
def fixed(*args, **kwargs):
try:
return original_format(*args, **kwargs)
except:
return ""
JSONReqFormatter.format = fixed
app = Sanic("myapp")
setup_json_logging(app, disable_json_access_log=False)
Now, instead of a error, it logs an empty line
An updated workaround:
original_format = JSONReqFormatter.format
def fixed(original_self, record, *args, **kwargs):
if hasattr(record, "request") and hasattr(record.request, "headers"):
return original_format(original_self, record, *args, **kwargs)
return ""
JSONReqFormatter.format = fixed
app = Sanic("myapp")
setup_json_logging(app, disable_json_access_log=False)
With the same "log empty line" problem
Found that the problem is solved if access_log is False on app.run:
app.run(
...
access_log=False,
)
The access log still happens because of the disable_json_access_log=False
Hi. Maybe I'm doing something wrong, but it doesn't want to work for for me.
Problem
Here is what I get when I use
disable_json_access_log=False
setup_json_logging(app, disable_json_access_log=False, configure_task_local_storage=False)
How to reproduce
cat Pipfile
cat app.py
In another terminal
curl localhost:8000/test
or browserlocalhost:8000/test
why I use
disable_json_access_log=False
When I use
disable_json_access_log=False
then I have logs in format I need, but there is an errorWhen I use
disable_json_access_log=True
it doesn't look like I wantThe goal to have all logs in
json
format (including access logs) Could you help me to fix it?