-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c2e8661
commit 27f620a
Showing
11 changed files
with
171 additions
and
142 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ | |
|
||
import toml | ||
|
||
from .utils import warn | ||
from .logs import warn | ||
|
||
# common strings | ||
internal = "internal" | ||
|
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,84 @@ | ||
import logging | ||
from dataclasses import dataclass | ||
|
||
from rich.logging import RichHandler | ||
|
||
# | ||
# Basic logging | ||
# | ||
|
||
logging.basicConfig( | ||
format="%(message)s", | ||
handlers=[RichHandler(level=logging.NOTSET, show_time=False)], | ||
) | ||
|
||
logger = logging.getLogger("halmos") | ||
|
||
|
||
def debug(text: str) -> None: | ||
logger.debug(text) | ||
|
||
|
||
def info(text: str) -> None: | ||
logger.info(text) | ||
|
||
|
||
def warn(text: str) -> None: | ||
logger.warning(text) | ||
|
||
|
||
def error(text: str) -> None: | ||
logger.error(text) | ||
|
||
|
||
# | ||
# Logging with filtering out duplicate log messages | ||
# | ||
|
||
|
||
class UniqueLoggingFilter(logging.Filter): | ||
def __init__(self): | ||
self.records = set() | ||
|
||
def filter(self, record): | ||
if record.msg in self.records: | ||
return False | ||
self.records.add(record.msg) | ||
return True | ||
|
||
|
||
logger_unique = logging.getLogger("halmos.unique") | ||
logger_unique.addFilter(UniqueLoggingFilter()) | ||
|
||
|
||
def debug_once(text: str) -> None: | ||
logger_unique.debug(text) | ||
|
||
|
||
# | ||
# Warnings with error code | ||
# | ||
|
||
WARNINGS_BASE_URL = "https://github.com/a16z/halmos/wiki/warnings" | ||
|
||
|
||
@dataclass | ||
class ErrorCode: | ||
code: str | ||
|
||
def url(self) -> str: | ||
return f"{WARNINGS_BASE_URL}#{self.code}" | ||
|
||
|
||
PARSING_ERROR = ErrorCode("parsing-error") | ||
INTERNAL_ERROR = ErrorCode("internal-error") | ||
LIBRARY_PLACEHOLDER = ErrorCode("library-placeholder") | ||
COUNTEREXAMPLE_INVALID = ErrorCode("counterexample-invalid") | ||
COUNTEREXAMPLE_UNKNOWN = ErrorCode("counterexample-unknown") | ||
UNSUPPORTED_OPCODE = ErrorCode("unsupported-opcode") | ||
REVERT_ALL = ErrorCode("revert-all") | ||
LOOP_BOUND = ErrorCode("loop-bound") | ||
|
||
|
||
def warn_code(error_code: ErrorCode, msg: str): | ||
logger.warning(f"{msg}\n(see {error_code.url()})") |
Oops, something went wrong.