-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Minor Cleanup of Structured Logging Module (#4266)
* cleanup structured logging module * update adapter logger to preserve new-style logging formatting
- Loading branch information
Nathaniel May
authored
Nov 17, 2021
1 parent
2241698
commit 719b202
Showing
8 changed files
with
206 additions
and
179 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
from abc import ABCMeta, abstractmethod | ||
from dataclasses import dataclass | ||
from datetime import datetime | ||
import os | ||
from typing import Any | ||
|
||
|
||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # | ||
# These base types define the _required structure_ for the concrete event # | ||
# types defined in types.py # | ||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # | ||
|
||
|
||
# in preparation for #3977 | ||
class TestLevel(): | ||
def level_tag(self) -> str: | ||
return "test" | ||
|
||
|
||
class DebugLevel(): | ||
def level_tag(self) -> str: | ||
return "debug" | ||
|
||
|
||
class InfoLevel(): | ||
def level_tag(self) -> str: | ||
return "info" | ||
|
||
|
||
class WarnLevel(): | ||
def level_tag(self) -> str: | ||
return "warn" | ||
|
||
|
||
class ErrorLevel(): | ||
def level_tag(self) -> str: | ||
return "error" | ||
|
||
|
||
@dataclass | ||
class ShowException(): | ||
# N.B.: | ||
# As long as we stick with the current convention of setting the member vars in the | ||
# `message` method of subclasses, this is a safe operation. | ||
# If that ever changes we'll want to reassess. | ||
def __post_init__(self): | ||
self.exc_info: Any = True | ||
self.stack_info: Any = None | ||
self.extra: Any = None | ||
|
||
|
||
# TODO add exhaustiveness checking for subclasses | ||
# top-level superclass for all events | ||
class Event(metaclass=ABCMeta): | ||
# fields that should be on all events with their default implementations | ||
ts: datetime = datetime.now() | ||
pid: int = os.getpid() | ||
# code: int | ||
|
||
# do not define this yourself. inherit it from one of the above level types. | ||
@abstractmethod | ||
def level_tag(self) -> str: | ||
raise Exception("level_tag not implemented for event") | ||
|
||
# Solely the human readable message. Timestamps and formatting will be added by the logger. | ||
# Must override yourself | ||
@abstractmethod | ||
def message(self) -> str: | ||
raise Exception("msg not implemented for cli event") | ||
|
||
# returns a dictionary representation of the event fields. You must specify which of the | ||
# available messages you would like to use (i.e. - e.message, e.cli_msg(), e.file_msg()) | ||
# used for constructing json formatted events. includes secrets which must be scrubbed at | ||
# the usage site. | ||
def to_dict(self, msg: str) -> dict: | ||
level = self.level_tag() | ||
return { | ||
'pid': self.pid, | ||
'msg': msg, | ||
'level': level if len(level) == 5 else f"{level} " | ||
} | ||
|
||
|
||
class File(Event, metaclass=ABCMeta): | ||
# Solely the human readable message. Timestamps and formatting will be added by the logger. | ||
def file_msg(self) -> str: | ||
# returns the event msg unless overriden in the concrete class | ||
return self.message() | ||
|
||
|
||
class Cli(Event, metaclass=ABCMeta): | ||
# Solely the human readable message. Timestamps and formatting will be added by the logger. | ||
def cli_msg(self) -> str: | ||
# returns the event msg unless overriden in the concrete class | ||
return self.message() |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
from dbt.events.types import Event | ||
from dbt.events.base_types import Event | ||
from typing import List | ||
|
||
|
||
|
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
from typing import ( | ||
Any, | ||
Optional, | ||
NamedTuple, | ||
Optional, | ||
) | ||
|
||
# N.B.: | ||
|
Oops, something went wrong.