simplecolorlogger 0.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .main import Logger
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
from colorama import Fore, Style, just_fix_windows_console
|
|
2
|
+
from time import gmtime, strftime
|
|
3
|
+
from datetime import datetime
|
|
4
|
+
from os import path, remove, makedirs
|
|
5
|
+
import sys
|
|
6
|
+
|
|
7
|
+
class Logger():
|
|
8
|
+
"""
|
|
9
|
+
A simple to use logger that provides colored log messages.
|
|
10
|
+
logging_level: int -> [0: Disabled, 1: INFO, 2: WARNING, 3: CRITICAL, 4: ERROR, 5: DEBUG]
|
|
11
|
+
Used to set the maximum logging level to be used.
|
|
12
|
+
default = 0
|
|
13
|
+
file_logging: bool -> Enable/Disable writing log file
|
|
14
|
+
default = False
|
|
15
|
+
log_save_location: str -> A relative path to the location where logs are save
|
|
16
|
+
default = "./logs"
|
|
17
|
+
log_save_name: str -> The generic name for the written log files
|
|
18
|
+
default = "log"
|
|
19
|
+
log_time_stamping: bool -> Enable/Disable appending a datestamp to log files
|
|
20
|
+
default = True
|
|
21
|
+
msg_time_stamping: bool -> Enable/Disable prepending a timestamp to log messages
|
|
22
|
+
default = True
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
_logging_level: int = 0
|
|
26
|
+
_file_logging: bool = False
|
|
27
|
+
_log_save_location: str = "./logs"
|
|
28
|
+
_log_save_name: str = "log"
|
|
29
|
+
_log_date_stamping: bool = True
|
|
30
|
+
_msg_time_stamping: bool = True
|
|
31
|
+
|
|
32
|
+
_lb: str = f"{Style.BRIGHT}{Fore.LIGHTCYAN_EX}[{Style.RESET_ALL}"
|
|
33
|
+
_rb: str = f"{Style.BRIGHT}{Fore.LIGHTCYAN_EX}]{Style.RESET_ALL}"
|
|
34
|
+
_col: str = f"{Style.BRIGHT}{Fore.LIGHTCYAN_EX} : {Style.RESET_ALL}"
|
|
35
|
+
_bar: str = f"{Style.BRIGHT}{Fore.LIGHTCYAN_EX} | {Style.RESET_ALL}"
|
|
36
|
+
_arw: str = f"{Style.BRIGHT}{Fore.LIGHTCYAN_EX} -> {Style.RESET_ALL}"
|
|
37
|
+
_lv1: str = f"{_lb}{Style.BRIGHT}{Fore.LIGHTBLUE_EX}INFO{Style.RESET_ALL}{_rb}{_bar}"
|
|
38
|
+
_lv2: str = f"{_lb}{Style.BRIGHT}{Fore.LIGHTRED_EX}WARNING{Style.RESET_ALL}{_rb}{_bar}"
|
|
39
|
+
_lv3: str = f"{_lb}{Style.BRIGHT}{Fore.LIGHTYELLOW_EX}CRITICAL{Style.RESET_ALL}{_rb}{_bar}"
|
|
40
|
+
_lv4: str = f"{_lb}{Style.BRIGHT}{Fore.RED}ERROR{Style.RESET_ALL}{_rb}{_bar}"
|
|
41
|
+
_lv5: str = f"{_lb}{Style.BRIGHT}{Fore.MAGENTA}DEBUG{Style.RESET_ALL}{_rb}{_bar}"
|
|
42
|
+
|
|
43
|
+
def __init__(self, logging_level: int, file_logging: bool = False, msg_time_stamping: bool = True, log_date_stamping: bool = True, log_save_location: str = "", log_save_name: str = "") -> None:
|
|
44
|
+
self._logging_level = logging_level
|
|
45
|
+
self._file_logging = file_logging
|
|
46
|
+
self._log_date_stamping = log_date_stamping
|
|
47
|
+
self._msg_time_stamping = msg_time_stamping
|
|
48
|
+
if not log_save_location == "": self._log_save_location = log_save_location
|
|
49
|
+
if not log_save_name == "": self._log_save_name = log_save_name
|
|
50
|
+
just_fix_windows_console()
|
|
51
|
+
|
|
52
|
+
def update_logging_level(self, logging_level: int) -> None:
|
|
53
|
+
"""
|
|
54
|
+
Update the current maximum logging level
|
|
55
|
+
"""
|
|
56
|
+
self._logging_level = logging_level
|
|
57
|
+
|
|
58
|
+
def update_file_logging(self, file_logging: bool) -> None:
|
|
59
|
+
"""
|
|
60
|
+
Update whether to save a log file
|
|
61
|
+
"""
|
|
62
|
+
self._file_logging = file_logging
|
|
63
|
+
|
|
64
|
+
def update_log_date_stamping(self, log_date_stamping: bool) -> None:
|
|
65
|
+
"""
|
|
66
|
+
Update whether to append a datestamp to log files
|
|
67
|
+
"""
|
|
68
|
+
self._log_date_stamping = log_date_stamping
|
|
69
|
+
|
|
70
|
+
def update_msg_time_stamping(self, msg_time_stamping: bool) -> None:
|
|
71
|
+
"""
|
|
72
|
+
Update whether to prepend a timestamp to logged message
|
|
73
|
+
"""
|
|
74
|
+
self._msg_time_stamping = msg_time_stamping
|
|
75
|
+
|
|
76
|
+
def update_log_save_location(self, log_save_location: str) -> None:
|
|
77
|
+
"""
|
|
78
|
+
Update the relative path of the log file save location
|
|
79
|
+
"""
|
|
80
|
+
self._log_save_location = log_save_location
|
|
81
|
+
|
|
82
|
+
def update_log_save_name(self, log_save_name: str) -> None:
|
|
83
|
+
"""
|
|
84
|
+
Update the log's generic name
|
|
85
|
+
"""
|
|
86
|
+
self._log_save_name = log_save_name
|
|
87
|
+
|
|
88
|
+
def log_message(self, text: str, level: int = 0, class_name: str = "Logger", method_name: str = "log_message") -> None:
|
|
89
|
+
"""
|
|
90
|
+
Used to both print and write a log message to the console and a file.
|
|
91
|
+
text: str -> The raw text to log
|
|
92
|
+
No Default
|
|
93
|
+
level: int -> The log level of the message. 0 in this context uses the Logger's current maxium
|
|
94
|
+
default: 0
|
|
95
|
+
class_name: str -> The name of the class the log is being sent from
|
|
96
|
+
default: "Logger"
|
|
97
|
+
method_name: str -> The name of the method the log is being sent from
|
|
98
|
+
default: "log_message"
|
|
99
|
+
"""
|
|
100
|
+
if level == 0: level = self._logging_level
|
|
101
|
+
if level <= self._logging_level and not self._logging_level == 0:
|
|
102
|
+
_msg_stamp = ""
|
|
103
|
+
_base = f"{self._lb}{Style.BRIGHT}{Fore.LIGHTGREEN_EX}{class_name}{Style.RESET_ALL}{self._col}{Style.BRIGHT}{Fore.LIGHTWHITE_EX}{method_name}{Style.RESET_ALL}{self._rb}{self._arw}{text}"
|
|
104
|
+
if self._msg_time_stamping: _msg_stamp = f"{datetime.now().strftime("[%I:%M:%S] :: ")}"
|
|
105
|
+
match level:
|
|
106
|
+
case 1:
|
|
107
|
+
sys.stdout.write(f"{_msg_stamp}{self._lv1}{_base}\n")
|
|
108
|
+
case 2:
|
|
109
|
+
sys.stdout.write(f"{_msg_stamp}{self._lv2}{_base}\n")
|
|
110
|
+
case 3:
|
|
111
|
+
sys.stdout.write(f"{_msg_stamp}{self._lv3}{_base}\n")
|
|
112
|
+
case 4:
|
|
113
|
+
sys.stdout.write(f"{_msg_stamp}{self._lv4}{_base}\n")
|
|
114
|
+
case 5:
|
|
115
|
+
sys.stdout.write(f"{_msg_stamp}{self._lv5}{_base}\n")
|
|
116
|
+
if self._file_logging:
|
|
117
|
+
_file_stamp = ""
|
|
118
|
+
if self._log_date_stamping: _file_stamp = f"-{strftime("%Y-%m-%d", gmtime())}"
|
|
119
|
+
if path.exists(f"{self._log_save_location}/"):
|
|
120
|
+
if path.exists(f"{self._log_save_location}/{self._log_save_location}{_file_stamp}"):
|
|
121
|
+
remove(f"{self._log_save_location}/{self._log_save_location}{_file_stamp}")
|
|
122
|
+
else:
|
|
123
|
+
makedirs(f"{self._log_save_location}/")
|
|
124
|
+
with open(f"{self._log_save_location}/{self._log_save_name}{_file_stamp}", "a") as log_file:
|
|
125
|
+
match level:
|
|
126
|
+
case 1:
|
|
127
|
+
log_file.write(f"{_msg_stamp}[INFO] | [{class_name} : {method_name}] -> {text}\n")
|
|
128
|
+
case 2:
|
|
129
|
+
log_file.write(f"{_msg_stamp}[WARNING] | [{class_name} : {method_name}] -> {text}\n")
|
|
130
|
+
case 3:
|
|
131
|
+
log_file.write(f"{_msg_stamp}[CRITICAL] | [{class_name} : {method_name}] -> {text}\n")
|
|
132
|
+
case 4:
|
|
133
|
+
log_file.write(f"{_msg_stamp}[ERROR] | [{class_name} : {method_name}] -> {text}\n")
|
|
134
|
+
case 5:
|
|
135
|
+
log_file.write(f"{_msg_stamp}[DEBUG] | [{class_name} : {method_name}] -> {text}\n")
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
simplecolorlogger/__init__.py,sha256=WJrLj_ooNmEFjNR4BG2DnjtLZrvGG2TjLzQ6wAE6eIw,25
|
|
2
|
+
simplecolorlogger/main.py,sha256=ovyx-BVOhj1zmy7SQCpEfEueTF1WfchUAJ1H5P--wh8,6696
|
|
3
|
+
simplecolorlogger-0.1.dist-info/METADATA,sha256=1DHPDe85jFZ73OZ4Nc4ROCcXnzpJT0oxnJjZaFfMFwM,113
|
|
4
|
+
simplecolorlogger-0.1.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
5
|
+
simplecolorlogger-0.1.dist-info/top_level.txt,sha256=9c-rTYuoS4O2zYQtbyn_G8a3-oftW_9BaUoEvN2lcYA,18
|
|
6
|
+
simplecolorlogger-0.1.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
simplecolorlogger
|