forked from airbytehq/airbyte
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🎉 CDK: use standard logger with custom handler
* CDK - using native logger with custom formatter * CDK - using native logger(fix exception and add trace) * CDK - using native logger in AirbyteEntrypoint * CDK - CHANGELOG.md * CDK - remove unnecessary imports * CDK - fixing according to PR review * CDK native logger airbytehq#1279 - annotations * CDK native logger airbytehq#1279 - fixing according to PR review * CDK standard logger airbytehq#1279 - tests * CDK standard logger airbytehq#1279 - reformat * Airbyte CDK airbytehq#1279 - improve docstrings * Airbyte CDK airbytehq#1279 - improve log levels * Airbyte CDK airbytehq#1279 - fix init get source name * Airbyte CDK airbytehq#1279 - update test licence * Airbyte CDK airbytehq#1279 - bump version
- Loading branch information
1 parent
fae6d47
commit d5c0499
Showing
9 changed files
with
168 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# | ||
# Copyright (c) 2021 Airbyte, Inc., all rights reserved. | ||
# | ||
|
||
|
||
import json | ||
from typing import Dict | ||
|
||
import pytest | ||
from airbyte_cdk.logger import AirbyteLogFormatter, init_logger | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def logger(): | ||
logger = init_logger("Test logger") | ||
return logger | ||
|
||
|
||
def test_formatter(logger, caplog): | ||
formatter = AirbyteLogFormatter() | ||
logger.info("Test formatter") | ||
record = caplog.records[0] | ||
formatted_record = formatter.format(record) | ||
formatted_record_data = json.loads(formatted_record) | ||
assert formatted_record_data.get("type") == "LOG" | ||
log = formatted_record_data.get("log") | ||
assert isinstance(log, Dict) | ||
level = log.get("level") | ||
message = log.get("message") | ||
assert level == "INFO" | ||
assert message == "Test formatter" | ||
|
||
|
||
def test_trace(logger, caplog): | ||
logger.trace("Test trace 1") | ||
record = caplog.records[0] | ||
assert record.levelname == "TRACE" | ||
assert record.message == "Test trace 1" | ||
|
||
|
||
def test_debug(logger, caplog): | ||
logger.debug("Test debug 1") | ||
record = caplog.records[0] | ||
assert record.levelname == "DEBUG" | ||
assert record.message == "Test debug 1" | ||
|
||
|
||
def test_info(logger, caplog): | ||
logger.info("Test info 1") | ||
logger.info("Test info 2") | ||
assert len(caplog.records) == 2 | ||
first_record = caplog.records[0] | ||
assert first_record.levelname == "INFO" | ||
assert first_record.message == "Test info 1" | ||
|
||
|
||
def test_warn(logger, caplog): | ||
logger.warn("Test warn 1") | ||
record = caplog.records[0] | ||
assert record.levelname == "WARNING" | ||
assert record.message == "Test warn 1" | ||
|
||
|
||
def test_error(logger, caplog): | ||
logger.error("Test error 1") | ||
record = caplog.records[0] | ||
assert record.levelname == "ERROR" | ||
assert record.message == "Test error 1" | ||
|
||
|
||
def test_fatal(logger, caplog): | ||
logger.fatal("Test fatal 1") | ||
record = caplog.records[0] | ||
assert record.levelname == "CRITICAL" | ||
assert record.message == "Test fatal 1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,8 +86,10 @@ definitions: | |
type: string | ||
enum: | ||
- FATAL | ||
- CRITICAL | ||
- ERROR | ||
- WARN | ||
- WARNING | ||
- INFO | ||
- DEBUG | ||
- TRACE | ||
|