-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. Another version bump of near-lake-frame with improvements related to logging. Specifically this PR which also migrated the fetch_latest_block function from here to there. 2. Adding a logger and replacing all print statements with log statements. Note that we explicitly filter out the noisy "missing shard" log (this is only temporary because I think the missing shard log should be debug instead of warning).
- Loading branch information
Showing
6 changed files
with
75 additions
and
51 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
network = "testnet" | ||
# gas station contract account id | ||
contract_id = "canhazgas.testnet" | ||
log_level = "info" |
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,37 @@ | ||
import logging | ||
|
||
|
||
class IgnoreFilter(logging.Filter): | ||
""" | ||
Customized Log filter that ignores a given message text. | ||
""" | ||
|
||
def __init__(self, ignored_message: str, name: str = "") -> None: | ||
super().__init__(name) | ||
self.ignored_message = ignored_message | ||
self.enabled = True | ||
|
||
def filter(self, record: logging.LogRecord) -> bool: | ||
if not self.enabled: | ||
return True | ||
return self.ignored_message not in record.getMessage() | ||
|
||
def set_ignored_message(self, message: str) -> None: | ||
"""Set a new message pattern to ignore.""" | ||
self.ignored_message = message | ||
|
||
def toggle_filter(self, enable: bool) -> None: | ||
"""Enable or disable the filter.""" | ||
self.enabled = enable | ||
|
||
def get_ignored_message(self) -> str: | ||
"""Get the current ignored message pattern.""" | ||
return self.ignored_message | ||
|
||
|
||
def set_logger(name: str, level: int | str) -> logging.Logger: | ||
logging.basicConfig(level=level) | ||
logging.getLogger("near_lake_framework").setLevel(logging.INFO) | ||
missing_shard_filter = IgnoreFilter("doesn't exist") | ||
logging.getLogger().addFilter(missing_shard_filter) | ||
return logging.getLogger(name) |
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,5 +1,5 @@ | ||
asyncio>=3.4.3 | ||
near-lake-framework>=0.0.8 | ||
near-lake-framework>=0.1.0 | ||
requests>=2.32.0 | ||
toml>=0.10.2 | ||
|
||
|