Comments (10)
@ianbrayoni you can actually supply those kwargs to the JSONRenderer class through the dumps_kw
argument. I ran into the same issue, but noticed this is the source code (snippet below):
class JSONRenderer(object):
"""
Render the `event_dict` using ``serializer(event_dict, **json_kw)``.
....
"""
def __init__(self, serializer=json.dumps, **dumps_kw):
self._dumps_kw = dumps_kw
self._dumps = serializer
def __call__(self, logger, name, event_dict):
return self._dumps(event_dict, default=_json_fallback_handler,
**self._dumps_kw)
from structlog.
I think you want structlog.processors.UnicodeEncoder
.
from structlog.
Is this Python 2.7? You need UnicodeEncoder
instead of UnicodeDecoder
on legacy Python versions.
from structlog.
@hynek
Thanks for your commentary first ^_^
and then
I had tried both, and I had debugged it with the debug tool in Pycharm, and I tried it onece again when I saw your commentary. It was no helped. Here is my demo main code. Thank you for caring me again ^_^
import structlog
import tornado.options
from tornado import autoreload
from tornado.httpserver import HTTPServer
from tornado.ioloop import IOLoop
from tornado.wsgi import WSGIContainer
from flask import Flask
app = Flask(__name__)
if __name__ == '__main__':
structlog.configure(
processors=[
structlog.processors.UnicodeEncoder(),
structlog.processors.KeyValueRenderer(
key_order=['event', 'request_id'],
),
],
context_class=structlog.threadlocal.wrap_dict(dict),
logger_factory=structlog.stdlib.LoggerFactory(),
)
tornado.options.parse_command_line()
http_server = HTTPServer(WSGIContainer(app))
http_server.listen(9998)
instance = IOLoop.instance()
autoreload.start(instance)
instance.start()
from structlog.
OK I’ve looked further into this and it’s interesting!
Python 2:
>>> print(repr('哈哈哈'))
'\xe5\x93\x88\xe5\x93\x88\xe5\x93\x88'
>>> print(repr(u'哈哈哈'))
u'\u54c8\u54c8\u54c8'
Python 3:
>>> print(repr('哈哈哈'))
'哈哈哈'
Python 3 has simply a much better Unicode support.
I am not 100% sure what to make of it though. :(
from structlog.
So I think I found a workaround by adding a new option to (KeyValue|Console)Renderer:
>>> import structlog, sys, logging
>>> structlog.get_logger().info("哈哈哈", some_key="哈哈哈")
2016-12-09 12:52.52 哈哈哈 some_key=哈哈哈
>>> handler = logging.StreamHandler(sys.stdout)
>>> root_logger = logging.getLogger()
>>> root_logger.addHandler(handler)
>>> structlog.configure(
... processors=[
... structlog.processors.UnicodeEncoder(),
... structlog.processors.KeyValueRenderer(
... key_order=['event', 'request_id'], repr_native_str=False
... ),
... ],
... context_class=structlog.threadlocal.wrap_dict(dict),
... logger_factory=structlog.stdlib.LoggerFactory(),
... )
>>> structlog.get_logger().warning("哈哈哈")
event=哈哈哈 request_id=None
It’s not on PyPI yet; would you mind testing it, if it works for you?
from structlog.
OK, I'll test it, and will tell you the result ,tks~~
from structlog.
It is worked!
And I am so exciting!!
I pip install form github, and the result is in the picture below
Thanks very much for solving this problem ~_~
If you push it to the PyPI, please kindly @ me here, thank you.
pip install git+https://github.com/hynek/structlog.git
from structlog.
It took a bit longer than I hoped, but 17.1 is on PyPI!
from structlog.
OK, thanks.
from structlog.
Related Issues (20)
- How can I intercept stdlib logging used in 3rd party library? HOT 1
- Add support for stdlib's stacklevel parameter
- Changing TimeStamper `key` to `"ts"` breaks ordering of logs for ConsoleRenderer HOT 3
- Traceback when using `stdlib.filter_by_level` with Python Standard Logging Library HOT 3
- structlog logger.exception doesn't accept positional arguments HOT 1
- How to disable logging? HOT 3
- How to configure CallsiteParameter so I can click on log lines in IDE and jump to the correct line in the file? HOT 3
- Please add documentation for how to configure logging to standard error HOT 1
- Allow renaming keys added by CallsiteParameterAdder
- question/feature request: Adjustable width in rich_traceback / Passing options to rich HOT 1
- Changes to behavior of `runtime_checkable()` in py 3.12 HOT 6
- WriteLogger log rotation HOT 2
- logs reader HOT 1
- Structlog does not work with tqdm HOT 4
- exc_info is not resolved properly when calling BoundLogger.exception HOT 5
- 'LoggerFactory' prevents structlog from logging DEBUG and INFO level logs HOT 1
- Any examples for configuration to use in Azure Functions HOT 1
- Version compatibility check for optional dependencies HOT 4
- "exception" is a possible log level from processors.add_log_level since 23.3.0 HOT 10
- `structlog.get_context` breaks from 23.2.0 to 23.3.0 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from structlog.