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

Create a bound logger in vdk-core #2802

Closed
DeltaMichael opened this issue Oct 17, 2023 · 0 comments
Closed

Create a bound logger in vdk-core #2802

DeltaMichael opened this issue Oct 17, 2023 · 0 comments
Assignees
Labels
enhancement New feature or request initiative: VDK Run Logs story Task for an Epic

Comments

@DeltaMichael
Copy link
Contributor

DeltaMichael commented Oct 17, 2023

Overview

Vdk users should have the option of binding additional context to their log statements. This should be provided out of the box by vdk-core.

Example:

import logging

class BoundLogger(logging.LoggerAdapter):
    def process(self, msg, kwargs):
        # merge bound extra dict with existing exra dict if any
        if "extra" in kwargs:
            kwargs["extra"] = {**self.extra, **kwargs["extra"]}
        else:
            kwargs["extra"] = self.extra
        return msg, kwargs

def bind_logger(log, context):
     return BoundLogger(log, context)

Somewhere else in core, plugin or data job code

from vdk.internal.core.logging import bind_logger
import logging

log = logging.getLogger(__name__)

bound = bind_logger(log, {"bound_key": "bound_value"})
bound.warning("From vdk_initialize", extra={"first_key": "first_value", "second_key": "second_value"})
bound.warning("Something else from vdk_initialize")

Then, with vdk-structlog installed and a metadata config like

logging_metadata=timestamp,level,file_name,line_number,vdk_job_name,bound_key,second_key

We should see the bound_key and second_key values in the logs. bound_key should be present for both statements. second_key should be present for just the first statement.

Acceptance criteria

  1. Above scenario is implemented and works with vdk-structlog
@DeltaMichael DeltaMichael added the story Task for an Epic label Oct 17, 2023
DeltaMichael added a commit that referenced this issue Oct 23, 2023
## Why?

As part of VEP-2448, we'd like to make structured logging pluggable

## What?

Create a vdk-structlog plugin. The plugin allows users to configure
logging metadata and logging format. It also works with bound loggers.

## How was this tested?

Installed the plugin and ran a data job locally with different
configurations

## White kind of change is this?

feature/non-breaking

## Follow-up

- #2802
- #2803
- #2810
- #2811
- #2812
- #2813
- #2814

Signed-off-by: Dilyan Marinov <mdilyan@vmware.com>
gageorgiev added a commit that referenced this issue Oct 23, 2023
This change introduces the VdkBoundLogger and addresses #2802.

Testing done: locally tested

Signed-off-by: Gabriel Georgiev <gageorgiev@vmware.com>
gageorgiev added a commit that referenced this issue Oct 26, 2023
This change introduces the VdkBoundLogger and addresses #2802.

Testing done: locally tested

Signed-off-by: Gabriel Georgiev <gageorgiev@vmware.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request initiative: VDK Run Logs story Task for an Epic
Projects
None yet
Development

No branches or pull requests

2 participants