-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from OWASP/dev
RELEASE: 0.12.2
- Loading branch information
Showing
14 changed files
with
387 additions
and
258 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,17 @@ | ||
from colorama import Fore, Style, init | ||
import logging | ||
|
||
|
||
init(autoreset=True) | ||
|
||
|
||
class ColoredLogger(logging.Formatter): | ||
grey = Fore.WHITE | ||
yellow = Fore.YELLOW + Style.BRIGHT | ||
red = Fore.RED | ||
bold_red = Fore.RED + Style.BRIGHT | ||
reset = "\x1b[0m" | ||
format = "%(asctime)s - %(name)s - %(levelname)s - %(message)s (%(filename)s:%(lineno)d)" | ||
from rich.console import Console | ||
from rich.logging import RichHandler | ||
|
||
FORMATS = { | ||
logging.DEBUG: grey + format, | ||
logging.INFO: grey + format, | ||
logging.WARNING: yellow + format, | ||
logging.ERROR: red + format, | ||
logging.CRITICAL: bold_red + format | ||
} | ||
|
||
def format(self, record): | ||
log_fmt = self.FORMATS.get(record.levelno) | ||
formatter = logging.Formatter(log_fmt) | ||
return formatter.format(record) | ||
|
||
|
||
def create_logger(logger_name:str, logging_level=logging.DEBUG): | ||
# create logger | ||
logger = logging.getLogger(logger_name) | ||
logger.setLevel(logging_level) | ||
|
||
# create console handler with a higher log level | ||
ch = logging.StreamHandler() | ||
ch.setLevel(logging.DEBUG) | ||
import logging | ||
|
||
ch.setFormatter(ColoredLogger()) | ||
|
||
logger.addHandler(ch) | ||
console = Console() | ||
|
||
return logger | ||
|
||
# create logger | ||
logging.basicConfig( | ||
format="%(message)s", | ||
datefmt="[%X]", | ||
handlers=[RichHandler( | ||
console=console, rich_tracebacks=True, tracebacks_show_locals=True)], | ||
) | ||
logger = logging.getLogger("OWASP-OFFAT") | ||
logger.setLevel(logging.DEBUG) |
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
Oops, something went wrong.