-
-
Notifications
You must be signed in to change notification settings - Fork 232
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make filter_by_level processor work with std lib logs #195
Make filter_by_level processor work with std lib logs #195
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also pls changelog.
@@ -461,7 +461,7 @@ def format(self, record): | |||
# would transform our dict into a str. | |||
ed = record.msg.copy() | |||
except AttributeError: | |||
logger = None | |||
logger = logging.getLogger(record.name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a better way to achieve this? It looks expensive to call getLogger on each log entry.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've got three ideas in my mind:
- We could make it so that users would have to manually set logger to
ProcessorFormatter
and then makeProcessorFormatter
to take value from there.
logger = logging.getLogger()
formatter = ProcessorFormatter(JSONRenderer())
handler = StreamHandler(sys.stdout)
handler.setFormatter(formatter)
handler.formatter.logger = logger
# Or via setter which we would create handler.formatter.set_logger(logger)
logger.addHandler(handler)
-
Make users patch
logging.Logger.makeRecord
so that it includesself
as_std_logger
. -
Create some kind of first use only cache (probably some dict with
key
name of logger andvalue
logger itself) which would look up logger only first time, store it into cache and take it from there next time.
Do you have anything better in mind?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer 1). ProcessorFormatter could take the logger
as a constructor argument.
Is anyone working on this issue? |
I'm afraid I dropped the ball here unfortunately. You still game @ZlatyChlapec ? |
fixed in #219, thanks anyway and sorry for my failure to respond in adequate time! |
When using
filter_by_level
processor withProcessorFormatter
it fails on std lib logs because ofstructlog/src/structlog/stdlib.py
Line 333 in c0aeab5
None
.