-
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.
- improve schema file (re-export it) - parse arguments to choose subcommand and other arguments
- Loading branch information
Showing
3 changed files
with
118 additions
and
27 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,19 +1,50 @@ | ||
from logging import DEBUG, Formatter, Logger, StreamHandler, getLogger | ||
import logging | ||
from enum import Enum | ||
from logging import Formatter, Logger, StreamHandler, getLogger | ||
from typing import Self | ||
|
||
__GLOBAL__LOGGER__NAME = "__global__logger__" | ||
|
||
|
||
class LogLevel(Enum): | ||
CRITICAL = "CRITICAL" | ||
ERROR = "ERROR" | ||
WARNING = "WARNING" | ||
INFO = "INFO" | ||
DEBUG = "DEBUG" | ||
NOTSET = "NOTSET" | ||
|
||
@property | ||
def underlying(self: Self) -> int: | ||
match self: | ||
case LogLevel.CRITICAL: | ||
return logging.CRITICAL | ||
case LogLevel.ERROR: | ||
return logging.ERROR | ||
case LogLevel.WARNING: | ||
return logging.WARNING | ||
case LogLevel.INFO: | ||
return logging.INFO | ||
case LogLevel.DEBUG: | ||
return logging.DEBUG | ||
case LogLevel.NOTSET: | ||
return logging.NOTSET | ||
case _: | ||
msg = "UNREACHABLE!" | ||
raise RuntimeError(msg) | ||
|
||
|
||
def get_logger() -> Logger: | ||
return getLogger(__GLOBAL__LOGGER__NAME) | ||
|
||
|
||
def setup_custom_logger(level: int = DEBUG) -> Logger: | ||
def setup_custom_logger(level: LogLevel = LogLevel.DEBUG) -> Logger: | ||
formatter = Formatter(fmt="%(asctime)s - %(levelname)s - %(module)s - %(message)s") | ||
|
||
handler = StreamHandler() | ||
handler.setFormatter(formatter) | ||
|
||
logger = get_logger() | ||
logger.setLevel(level) | ||
logger.setLevel(level.underlying) | ||
logger.addHandler(handler) | ||
return logger |