Skip to content

Commit

Permalink
⚡🎨 Update(utils) colors in console colorizer & add new placeholders
Browse files Browse the repository at this point in the history
  • Loading branch information
MEHRSHAD-MIRSHEKARY committed Oct 16, 2024
1 parent a630d4c commit d208ebc
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
6 changes: 3 additions & 3 deletions django_logging/constants/log_format_options.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
FORMAT_OPTIONS = {
1: "%(levelname)s | %(asctime)s | %(module)s | %(message)s | %(context)s",
2: "%(levelname)s | %(asctime)s | %(context)s | %(message)s",
3: "%(levelname)s | %(context)s | %(message)s",
2: "%(levelname)s | %(asctime)s | %(context)s | %(message)s | %(exc_text)s",
3: "%(levelname)s | %(context)s | %(message)s | %(stack_info)s",
4: "%(context)s | %(asctime)s - %(name)s - %(levelname)s - %(message)s",
5: "%(levelname)s | %(message)s | %(context)s | [in %(pathname)s:%(lineno)d]",
6: "%(asctime)s | %(context)s | %(levelname)s | %(message)s",
6: "%(asctime)s | %(context)s | %(levelname)s | %(message)s | %(exc_info)s",
7: "%(levelname)s | %(asctime)s | %(context)s | in %(module)s: %(message)s",
8: "%(levelname)s | %(context)s | %(message)s | [%(filename)s:%(lineno)d]",
9: "[%(asctime)s] | %(levelname)s | %(context)s | in %(module)s: %(message)s",
Expand Down
4 changes: 4 additions & 0 deletions django_logging/constants/log_format_specifiers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
LOG_FORMAT_SPECIFIERS = [
"asctime",
"created",
"exc_info",
"exc_text",
"relativeCreated",
"msecs",
"levelname",
Expand All @@ -12,8 +14,10 @@
"lineno",
"funcName",
"process",
"processName",
"thread",
"threadName",
"message",
"stack_info",
"context",
]
10 changes: 7 additions & 3 deletions django_logging/utils/console_colorizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,27 @@
def colorize_log_format(log_format: str, levelname: str) -> str:
colors = AnsiColors()
color_mapping = {
"%(asctime)s": f"{colors.BRIGHT_YELLOW}%(asctime)s{colors.RESET}",
"%(asctime)s": f"{colors.BRIGHT_BLUE}%(asctime)s{colors.RESET}",
"%(created)f": f"{colors.BRIGHT_BLUE}%(created)f{colors.RESET}",
"%(relativeCreated)d": f"{colors.MAGENTA}%(relativeCreated)d{colors.RESET}",
"%(msecs)d": f"{colors.YELLOW}%(msecs)d{colors.RESET}",
"%(levelname)s": f"{LOG_LEVEL_COLORS.get(levelname, '')}%(levelname)s{colors.RESET}",
"%(levelno)d": f"{colors.RED}%(levelno)d{colors.RESET}",
"%(exc_info)s": f"{colors.RED}%(exc_info)s{colors.RESET}",
"%(exc_text)s": f"{colors.RED}%(exc_text)s{colors.RESET}",
"%(name)s": f"{colors.BRIGHT_MAGENTA}%(name)s{colors.RESET}",
"%(module)s": f"{colors.PINK}%(module)s{colors.RESET}",
"%(stack_info)s": f"{colors.YELLOW}%(stack_info)s{colors.RESET}",
"%(filename)s": f"{colors.YELLOW}%(filename)s{colors.RESET}",
"%(pathname)s": f"{colors.CYAN}%(pathname)s{colors.RESET}",
"%(lineno)d": f"{colors.RED}%(lineno)d{colors.RESET}",
"%(lineno)d": f"{colors.LIGHT_PURPLE}%(lineno)d{colors.RESET}",
"%(funcName)s": f"{colors.BRIGHT_BLUE}%(funcName)s{colors.RESET}",
"%(process)d": f"{colors.MAGENTA}%(process)d{colors.RESET}",
"%(processName)s": f"{colors.MAGENTA}%(processName)s{colors.RESET}",
"%(thread)d": f"{colors.CYAN}%(thread)d{colors.RESET}",
"%(threadName)s": f"{colors.BRIGHT_MAGENTA}%(threadName)s{colors.RESET}",
"%(message)s": f"{colors.ITALIC}%(message)s{colors.RESET}",
"%(context)s": f"{colors.CYAN}%(context)s{colors.RESET}",
"%(context)s": f"{colors.MAGENTA}%(context)s{colors.RESET}",
}

for placeholder, colorized in color_mapping.items():
Expand Down

0 comments on commit d208ebc

Please sign in to comment.