Skip to content
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

Closed
wants to merge 1 commit into from
Closed

Make filter_by_level processor work with std lib logs #195

wants to merge 1 commit into from

Conversation

ZlatyChlapec
Copy link
Contributor

When using filter_by_level processor with ProcessorFormatter it fails on std lib logs because of

if logger.isEnabledFor(_NAME_TO_LEVEL[name]):
being called on None.

Copy link
Owner

@hynek hynek left a 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)
Copy link
Owner

@hynek hynek Feb 24, 2019

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.

Copy link
Contributor Author

@ZlatyChlapec ZlatyChlapec Feb 25, 2019

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:

  1. We could make it so that users would have to manually set logger to ProcessorFormatter and then make ProcessorFormatter 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)
  1. Make users patch logging.Logger.makeRecord so that it includes self as _std_logger.

  2. Create some kind of first use only cache (probably some dict with key name of logger and value 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?

Copy link
Contributor

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.

@rasto2211
Copy link
Contributor

Is anyone working on this issue?

@hynek
Copy link
Owner

hynek commented Jul 20, 2019

I'm afraid I dropped the ball here unfortunately. You still game @ZlatyChlapec ?

@hynek
Copy link
Owner

hynek commented Aug 15, 2019

fixed in #219, thanks anyway and sorry for my failure to respond in adequate time!

@hynek hynek closed this Aug 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants