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

🎉 CDK: use standard logger with custom handler #6085

Merged
merged 17 commits into from
Oct 12, 2021

Conversation

vitaliizazmic
Copy link
Contributor

What

Use standard logger with custom handler

Closes #1279

How

Create according to issue AirbyteLogFormatter and AirbyteNativeLogger, which inherits logging.Logger.

@github-actions github-actions bot added the CDK Connector Development Kit label Sep 15, 2021
logging.Logger.__init__(self, name)
self.valid_log_types = {"FATAL": 50, "ERROR": 40, "WARN": 30, "INFO": 20, "DEBUG": 10, "TRACE": 5}

def log_by_prefix(self, msg, default_level):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add docstrings please

@@ -1,5 +1,8 @@
# Changelog

## 0.1.19
Use standard logger with custom handler
Copy link
Contributor

@keu keu Sep 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Use standard logger with custom handler
Use python standard logging instead of custom class

Copy link
Contributor

@keu keu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we have simple test for this?

Copy link
Contributor

@gaart gaart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree with @keu comments

@vitaliizazmic
Copy link
Contributor Author

can we have simple test for this?

I need advice how to better test logging.

@vitaliizazmic vitaliizazmic requested a review from keu September 17, 2021 13:10
@vitaliizazmic vitaliizazmic self-assigned this Sep 17, 2021
def get_logger():
logging.setLoggerClass(AirbyteNativeLogger)
logging.addLevelName(TRACE_LEVEL_NUM, "TRACE")
logger = logging.getLogger("airbyte.source.zabbix")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again, why did you hardcode this name?

Copy link
Contributor

@keu keu Sep 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, you need to set up this for root-level logger only. We are not particularly interested in return result, this will configure global object, so all loggers derived from root will follow this configuration, i.e.

logging.info(...)

will work as intended

@@ -45,7 +45,7 @@ class Stream(ABC):
"""

# Use self.logger in subclasses to log any messages
logger = AirbyteLogger() # TODO use native "logging" loggers with custom handlers
logger = get_logger()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
logger = get_logger()
@property
def logger(self):
return logging.getLogger(f'streams.{self.name}')

logging.setLoggerClass(AirbyteNativeLogger)
logging.addLevelName(TRACE_LEVEL_NUM, "TRACE")
logger = logging.getLogger("airbyte.source.zabbix")
logger.setLevel(TRACE_LEVEL_NUM)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also please use dict like configuration

    LOGGING_CONFIG = {
        'version': 1,
        'disable_existing_loggers': False,
        'formatters': {
            'airbyte': {
                'class': 'AirbyteLogFormatter,
                'format': '%(message)s'
            },
        },
        'handlers': {
            'console': {
                'class': 'logging.StreamHandler',
                'formatter': 'simple',
                'level': 'TRACE'
            },
        },
        'root': {
            'handlers': ['console'],
            'level': 'TRACE'
        }
    }
    logging.config.dictConfig(config)

return logger


class AirbyteLogFormatter(logging.Formatter):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

docstrings



class AirbyteLogFormatter(logging.Formatter):
def format(self, record):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

annotations



class AirbyteNativeLogger(logging.Logger):
def __init__(self, name):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

docstrings explaining why do we this class would be nice


class AirbyteNativeLogger(logging.Logger):
def __init__(self, name):
logging.Logger.__init__(self, name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
logging.Logger.__init__(self, name)
super().__init__(name)

Copy link
Contributor

@keu keu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see comments

@CLAassistant
Copy link

CLAassistant commented Sep 27, 2021

CLA assistant check
All committers have signed the CLA.

@vitaliizazmic vitaliizazmic requested a review from gaart September 30, 2021 16:17
@keu
Copy link
Contributor

keu commented Oct 4, 2021

@vitaliizazmic to test logging try to mock stdout, init logging and log different messages with different levels


class AirbyteEntrypoint(object):
def __init__(self, source: Source):
self.source = source
self.logger = init_logger(source.name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!

# Conflicts:
#	airbyte-cdk/python/CHANGELOG.md
#	airbyte-cdk/python/setup.py
@vitaliizazmic vitaliizazmic temporarily deployed to more-secrets October 12, 2021 14:34 Inactive
@vitaliizazmic
Copy link
Contributor Author

vitaliizazmic commented Oct 12, 2021

/publish-cdk dry-run=false

https://github.com/airbytehq/airbyte/actions/runs/1333576525
https://github.com/airbytehq/airbyte/actions/runs/1333576525
https://github.com/airbytehq/airbyte/actions/runs/1333576525
https://github.com/airbytehq/airbyte/actions/runs/1333576525

@vitaliizazmic
Copy link
Contributor Author

vitaliizazmic commented Oct 12, 2021

/publish-cdk dry-run=false

🕑 https://github.com/airbytehq/airbyte/actions/runs/1334000460
https://github.com/airbytehq/airbyte/actions/runs/1334000460

@vitaliizazmic vitaliizazmic temporarily deployed to more-secrets October 12, 2021 16:33 Inactive
@vitaliizazmic vitaliizazmic temporarily deployed to more-secrets October 12, 2021 16:52 Inactive
@vitaliizazmic
Copy link
Contributor Author

vitaliizazmic commented Oct 12, 2021

/publish-cdk dry-run=false

🕑 https://github.com/airbytehq/airbyte/actions/runs/1334153204
https://github.com/airbytehq/airbyte/actions/runs/1334153204

@vitaliizazmic vitaliizazmic temporarily deployed to more-secrets October 12, 2021 17:22 Inactive
@vitaliizazmic vitaliizazmic temporarily deployed to more-secrets October 12, 2021 17:32 Inactive
@vitaliizazmic vitaliizazmic merged commit d5c0499 into master Oct 12, 2021
@vitaliizazmic vitaliizazmic deleted the vitalii/1279_cdk_standard_logger branch October 12, 2021 17:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/protocol CDK Connector Development Kit
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use standard logger with custom handler in python integrations
5 participants