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

Add TraceLoggingFilter #1110

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

gukoff
Copy link
Contributor

@gukoff gukoff commented Mar 6, 2022

Filters are another, flexible way to add contextual information to the logs.

A filter can be attached to both a Logger and a Handler, allowing for more granular control on how to add contextual information to a log record.

E.g., a filter can be attached only to a opencensus export handler. And this will affect all log records emitted to handler, even if you use plain logging.info(...) instead of logging.getLogger(__name__).info(...).

Example:

def configure_logging():
    handler = AzureLogHandler(
        connection_string=app_insights_conn_str,
        sampler=AlwaysOnSampler(),
        credential=credential,
    )
    root = logging.getLogger()
    root.addHandler(handler)
    handler.addFilter(TraceLoggingFilter())

Filters are another, flexible way to add contextual information to the logs.

A filter can be attached to both a Logger and a Handler, allowing for more granular control on how to add the fields. E.g. a filter can be attached only to a specific opencensus export handler, it can be added anytime in the runtime. And this will affect all loggers using this handler, whether they were constructed before or after adding a filter (unlike with a custom Logger or Adapter).
@google-cla
Copy link

google-cla bot commented Mar 6, 2022

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

For more information, open the CLA check for this pull request.

@gukoff
Copy link
Contributor Author

gukoff commented May 31, 2022

Friendly ping? (:

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.

None yet

1 participant