-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨⚡ feat(constants): add default_settings & type annotations file
- Introduced default settings for logging configurations, such as LOG_DIR, LOG_FILE_LEVELS, and LOG_DATE_FORMAT. - Refactored the package to include config types using type annotations to improve code clarity and maintainability. This commit enhances the robustness and readability of the Django logging package, making it easier to maintain and extend.
- Loading branch information
1 parent
ddcab0c
commit 075e805
Showing
4 changed files
with
97 additions
and
1 deletion.
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 |
---|---|---|
@@ -1 +1,12 @@ | ||
from .format_options import FORMAT_OPTIONS | ||
from .default_settings import ( | ||
DEFAULT_INITIALIZATION_MESSAGE_ENABLED, | ||
DEFAULT_LOG_FILE_FORMATS, | ||
DEFAULT_LOG_CONSOLE_COLORIZE, | ||
DEFAULT_LOG_CONSOLE_FORMAT, | ||
DEFAULT_LOG_CONSOLE_LEVEL, | ||
DEFAULT_LOG_DATE_FORMAT, | ||
DEFAULT_LOG_DIR, | ||
DEFAULT_LOG_EMAIL_NOTIFIER, | ||
DEFAULT_LOG_FILE_LEVELS, | ||
) |
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,53 @@ | ||
import os | ||
|
||
from django_logging.constants.config_types import ( | ||
LogFileFormatsType, | ||
LOG_DIR_TYPE, | ||
LOG_FILE_LEVELS_TYPE, | ||
LOG_CONSOLE_FORMAT_TYPE, | ||
LOG_CONSOLE_LEVEL_TYPE, | ||
LOG_CONSOLE_COLORIZE_TYPE, | ||
LOG_DATE_FORMAT_TYPE, | ||
INITIALIZATION_MESSAGE_ENABLED_TYPE, | ||
LogEmailNotifierType, | ||
) | ||
|
||
# Default directory for logs | ||
DEFAULT_LOG_DIR: LOG_DIR_TYPE = os.path.join(os.getcwd(), "logs") | ||
|
||
# Default log levels | ||
DEFAULT_LOG_FILE_LEVELS: LOG_FILE_LEVELS_TYPE = [ | ||
"DEBUG", | ||
"INFO", | ||
"WARNING", | ||
"ERROR", | ||
"CRITICAL", | ||
] | ||
|
||
|
||
# Default log date format | ||
DEFAULT_LOG_DATE_FORMAT: LOG_DATE_FORMAT_TYPE = "%Y-%m-%d %H:%M:%S" | ||
|
||
DEFAULT_INITIALIZATION_MESSAGE_ENABLED: INITIALIZATION_MESSAGE_ENABLED_TYPE = True | ||
|
||
DEFAULT_LOG_FILE_FORMATS: LogFileFormatsType = { | ||
"DEBUG": 1, | ||
"INFO": 1, | ||
"WARNING": 1, | ||
"ERROR": 1, | ||
"CRITICAL": 1, | ||
} | ||
|
||
DEFAULT_LOG_CONSOLE_LEVEL: LOG_CONSOLE_LEVEL_TYPE = "DEBUG" | ||
|
||
DEFAULT_LOG_CONSOLE_FORMAT: LOG_CONSOLE_FORMAT_TYPE = 1 | ||
|
||
DEFAULT_LOG_CONSOLE_COLORIZE: LOG_CONSOLE_COLORIZE_TYPE = True | ||
|
||
DEFAULT_LOG_EMAIL_NOTIFIER: LogEmailNotifierType = { | ||
"ENABLE": False, | ||
"NOTIFY_ERROR": False, | ||
"NOTIFY_CRITICAL": False, | ||
"LOG_FORMAT": 1, | ||
"USE_TEMPLATE": True, | ||
} |
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,32 @@ | ||
from typing import TypedDict, Union, List, Literal | ||
|
||
FormatOption = Union[int, str] | ||
|
||
|
||
class LogEmailNotifierType(TypedDict, total=False): | ||
ENABLE: bool | ||
NOTIFY_ERROR: bool | ||
NOTIFY_CRITICAL: bool | ||
LOG_FORMAT: FormatOption | ||
USE_TEMPLATE: bool | ||
|
||
|
||
LogLevel = Literal["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"] | ||
|
||
|
||
class LogFileFormatsType(TypedDict, total=False): | ||
DEBUG: FormatOption | ||
INFO: FormatOption | ||
WARNING: FormatOption | ||
ERROR: FormatOption | ||
CRITICAL: FormatOption | ||
|
||
|
||
# Type Aliases for other configurations | ||
LOG_DIR_TYPE = str | ||
LOG_FILE_LEVELS_TYPE = List[str] | ||
LOG_DATE_FORMAT_TYPE = str | ||
INITIALIZATION_MESSAGE_ENABLED_TYPE = bool | ||
LOG_CONSOLE_LEVEL_TYPE = LogLevel | ||
LOG_CONSOLE_FORMAT_TYPE = FormatOption | ||
LOG_CONSOLE_COLORIZE_TYPE = bool |