-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added run_parallel functions and logger for logging
- Loading branch information
1 parent
0131a34
commit 75ad51c
Showing
4 changed files
with
193 additions
and
143 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,49 @@ | ||
import os | ||
import logging | ||
|
||
EXEC_INFO = True if os.getenv("EXEC_INFO") == "True" else False | ||
LOG_HANDLER = os.getenv("LOG_HANDLER", "Stream") | ||
LOG_FILE_PATH = os.getenv("LOG_FILE_PATH", "app.log") | ||
LOGLEVEL = os.getenv('LOGLEVEL', 'INFO').upper() | ||
|
||
if LOG_HANDLER not in {"File", "Stream"}: | ||
LOG_HANDLER = "Stream" | ||
|
||
if LOGLEVEL not in {"CRITICAL", "ERROR", "WARNING", "INFO", "DEBUG", "NOTSET"}: | ||
LOGLEVEL = "INFO" | ||
|
||
|
||
class CustomFormatter(logging.Formatter): | ||
|
||
grey = "\x1b[38;20m" | ||
yellow = "\x1b[33;20m" | ||
red = "\x1b[31;20m" | ||
bold_red = "\x1b[31;1m" | ||
reset = "\x1b[0m" | ||
format = "%(asctime)s - %(name)s - %(levelname)s - %(message)s (%(filename)s:%(lineno)d)" # noqa | ||
|
||
FORMATS = { | ||
logging.DEBUG: grey + format + reset, | ||
logging.INFO: grey + format + reset, | ||
logging.WARNING: yellow + format + reset, | ||
logging.ERROR: red + format + reset, | ||
logging.CRITICAL: bold_red + format + reset | ||
} | ||
|
||
def format(self, record): | ||
log_fmt = self.FORMATS.get(record.levelno) | ||
formatter = logging.Formatter(log_fmt) | ||
return formatter.format(record) | ||
|
||
|
||
logger = logging.getLogger("TargetServerValidator") | ||
logger.setLevel(getattr(logging, LOGLEVEL)) # Add this line | ||
|
||
if LOG_HANDLER == "File": | ||
ch = logging.FileHandler(LOG_FILE_PATH, mode="a") | ||
else: | ||
ch = logging.StreamHandler() | ||
|
||
ch.setFormatter(CustomFormatter()) | ||
|
||
logger.addHandler(ch) |
Oops, something went wrong.