-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Adapter logging interface #4161
Closed
nathaniel-may
wants to merge
14
commits into
feature/structured-logging
from
adapter-logging-interface
Closed
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
3453bb3
add event type modeling and fire_event calls
d627701
update flake8 command with per-file-ignore
1718831
flake8 fixes
16c63b7
revert flake8 command change
9caf39d
flake8 fixes
e31ff4a
move comment block
f203e0d
add one more event that actually has data
4e4e81a
flake8 fixes
c750a06
add adapter logging interface
222af30
fix rebase mistakes
1e07443
add test for documented adapter maintainer interface
3a495a7
add exception method to interface
e35106d
integrate new exception logging model
e726824
update postgres adapter to use new logger
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .adapter_endpoint import AdapterLogger # noqa: F401 |
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,86 @@ | ||
from dataclasses import dataclass | ||
from dbt.events.functions import fire_event | ||
from dbt.events.types import ( | ||
AdapterEventDebug, AdapterEventInfo, AdapterEventWarning, AdapterEventError | ||
) | ||
from typing import Any | ||
|
||
|
||
@dataclass | ||
class AdapterLogger(): | ||
name: str | ||
|
||
def debug( | ||
self, | ||
msg: str, | ||
exc_info: Any = None, | ||
stack_info: Any = None, | ||
extra: Any = None | ||
): | ||
event = AdapterEventDebug(name=self.name, raw_msg=msg) | ||
|
||
event.exc_info = exc_info | ||
event.stack_info = stack_info | ||
event.extra = extra | ||
|
||
fire_event(event) | ||
|
||
def info( | ||
self, | ||
msg: str, | ||
exc_info: Any = None, | ||
stack_info: Any = None, | ||
extra: Any = None | ||
): | ||
event = AdapterEventInfo(name=self.name, raw_msg=msg) | ||
|
||
event.exc_info = exc_info | ||
event.stack_info = stack_info | ||
event.extra = extra | ||
|
||
fire_event(event) | ||
|
||
def warning( | ||
self, | ||
msg: str, | ||
exc_info: Any = None, | ||
stack_info: Any = None, | ||
extra: Any = None | ||
): | ||
event = AdapterEventWarning(name=self.name, raw_msg=msg) | ||
|
||
event.exc_info = exc_info | ||
event.stack_info = stack_info | ||
event.extra = extra | ||
|
||
fire_event(event) | ||
|
||
def error( | ||
self, | ||
msg: str, | ||
exc_info: Any = None, | ||
stack_info: Any = None, | ||
extra: Any = None | ||
): | ||
event = AdapterEventError(name=self.name, raw_msg=msg) | ||
|
||
event.exc_info = exc_info | ||
event.stack_info = stack_info | ||
event.extra = extra | ||
|
||
fire_event(event) | ||
|
||
def exception( | ||
self, | ||
msg: str, | ||
exc_info: Any = True, # this default is what makes this method different | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like this call out. |
||
stack_info: Any = None, | ||
extra: Any = None | ||
): | ||
event = AdapterEventError(name=self.name, raw_msg=msg) | ||
|
||
event.exc_info = exc_info | ||
event.stack_info = stack_info | ||
event.extra = extra | ||
|
||
fire_event(event) |
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,19 @@ | ||
from unittest import mock, TestCase | ||
|
||
|
||
class TestFlags(TestCase): | ||
|
||
def setUp(self): | ||
pass | ||
|
||
# this interface is documented for adapter maintainers to plug into | ||
# so we should test that it at the very least doesn't explode. | ||
def test_adapter_logging_interface(self): | ||
from dbt.events import AdapterLogger | ||
logger = AdapterLogger("dbt_tests") | ||
logger.debug("debug message") | ||
logger.info("info message") | ||
logger.warning("warning message") | ||
logger.error("error message") | ||
logger.exception("exception message") | ||
self.assertTrue(True) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍