d4rktg 0.2.9__py3-none-any.whl → 0.3.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.
d4rk/Logs/_logger.py
CHANGED
@@ -1,10 +1,19 @@
|
|
1
1
|
# src/Log/_logger_config.py
|
2
2
|
|
3
3
|
import os
|
4
|
+
import sys
|
4
5
|
import logging
|
6
|
+
|
5
7
|
from datetime import datetime, timezone, timedelta
|
6
8
|
from logging.handlers import TimedRotatingFileHandler
|
7
9
|
|
10
|
+
try:
|
11
|
+
import colorama
|
12
|
+
colorama.init(autoreset=True)
|
13
|
+
COLORAMA_AVAILABLE = True
|
14
|
+
except ImportError:
|
15
|
+
COLORAMA_AVAILABLE = False
|
16
|
+
|
8
17
|
def get_timezone_offset(time_zone: str = "00:00") -> timezone:
|
9
18
|
if time_zone:
|
10
19
|
try:
|
@@ -20,6 +29,18 @@ def get_timezone_offset(time_zone: str = "00:00") -> timezone:
|
|
20
29
|
TZ = get_timezone_offset(os.getenv("TIME_ZONE", "05:30"))
|
21
30
|
|
22
31
|
class TimeZoneFormatter(logging.Formatter):
|
32
|
+
|
33
|
+
def __init__(self, fmt, datefmt=None, use_colors=False):
|
34
|
+
super().__init__(fmt, datefmt)
|
35
|
+
self.use_colors = use_colors
|
36
|
+
self.COLORS = {
|
37
|
+
logging.DEBUG: "\033[36m", # Cyan
|
38
|
+
logging.INFO: "\033[32m", # Green
|
39
|
+
logging.WARNING: "\033[33m", # Yellow
|
40
|
+
logging.ERROR: "\033[31m", # Red
|
41
|
+
logging.CRITICAL: "\033[41m",# Red background
|
42
|
+
}
|
43
|
+
self.RESET = "\033[0m"
|
23
44
|
def converter(self, timestamp):
|
24
45
|
dt = datetime.fromtimestamp(timestamp, tz=timezone.utc)
|
25
46
|
return dt.astimezone(TZ).timetuple()
|
@@ -31,6 +52,12 @@ class TimeZoneFormatter(logging.Formatter):
|
|
31
52
|
return time_zone_time.strftime(datefmt)
|
32
53
|
else:
|
33
54
|
return time_zone_time.strftime('%Y-%m-%d %H:%M:%S %z')
|
55
|
+
|
56
|
+
def format(self, record):
|
57
|
+
message = super().format(record)
|
58
|
+
if self.use_colors and record.levelno in self.COLORS:
|
59
|
+
return f"{self.COLORS[record.levelno]}{message}{self.RESET}"
|
60
|
+
return message
|
34
61
|
|
35
62
|
def setup_logger(name=__name__, log_level=logging.INFO):
|
36
63
|
log_dir = "logs"
|
@@ -55,11 +82,12 @@ def setup_logger(name=__name__, log_level=logging.INFO):
|
|
55
82
|
|
56
83
|
console_handler = logging.StreamHandler()
|
57
84
|
console_handler.setLevel(log_level)
|
58
|
-
|
85
|
+
use_colors = sys.stdout.isatty() and COLORAMA_AVAILABLE
|
59
86
|
# Create formatter with Sri Lanka timezone
|
60
87
|
formatter = TimeZoneFormatter(
|
61
88
|
'%(asctime)s - %(name)s - %(funcName)s:%(lineno)d - %(levelname)s - %(message)s',
|
62
|
-
datefmt='%Y-%m-%d %H:%M:%S'
|
89
|
+
datefmt='%Y-%m-%d %H:%M:%S',
|
90
|
+
use_colors=use_colors
|
63
91
|
)
|
64
92
|
|
65
93
|
file_handler.setFormatter(formatter)
|
@@ -5,7 +5,7 @@ d4rk/Handlers/__init__.py,sha256=lO1b7Tnu3GWgwcJmX5qepiNqaBBi6qTgjj0SlzVUyEA,63
|
|
5
5
|
d4rk/Handlers/_bot.py,sha256=v2XBzO0FUU9y6F9V9B8N2P2rrxmGZUC3u9xZg_2x7ik,11002
|
6
6
|
d4rk/Handlers/_scheduler.py,sha256=AyqexO4nxZlIzRfU9vWTfJtTWQVQmP4de7GRPg-3JkA,1236
|
7
7
|
d4rk/Logs/__init__.py,sha256=mXWD5jXnyH3_AvS7K_ki3iw5BpoEAvrDFbmr-iEFNnY,22
|
8
|
-
d4rk/Logs/_logger.py,sha256=
|
8
|
+
d4rk/Logs/_logger.py,sha256=4oykGNkG3BJ7ZfHlkWTrwQna2FlGEFF2EZ5njJGYwFs,3335
|
9
9
|
d4rk/Models/__init__.py,sha256=7bYM2c5Uk_VEg7NxIGH2EcEXGcAguwxvH23-Gy1orMM,100
|
10
10
|
d4rk/Models/_commands.py,sha256=U831pYCQbAYxyn3t6f49Wlk7vWycynR0sjxIOy0xjS8,2816
|
11
11
|
d4rk/Models/_movie_title.py,sha256=Xp8eafBP-kD3MxAdeNcb7EyiAojn5fDQ18la7vxrg10,812
|
@@ -17,7 +17,7 @@ d4rk/Utils/_ip.py,sha256=KJJW2QSngshIVWCO5YPXF1wj4IPQzVN5oFofpfzlU5w,559
|
|
17
17
|
d4rk/Utils/_movie_parser.py,sha256=eiy1YVSu9fgk9pIXnMojJkWhW6SbdewKGF0ATk2qZoA,3440
|
18
18
|
d4rk/Utils/_ractions.py,sha256=wOVPyoFnbDuMgoP6NF_gLO1DYcfhERC0trdAK1jWSE8,2170
|
19
19
|
d4rk/Utils/_terminal.py,sha256=Anu4OcffY3v6LMOrCskP1cHrJIliomo1Hjownbhh2sQ,125
|
20
|
-
d4rktg-0.
|
21
|
-
d4rktg-0.
|
22
|
-
d4rktg-0.
|
23
|
-
d4rktg-0.
|
20
|
+
d4rktg-0.3.1.dist-info/METADATA,sha256=m0oBg_wh0CxNoWBftegeCES_hO7FksXVjUxTcCvczv4,652
|
21
|
+
d4rktg-0.3.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
22
|
+
d4rktg-0.3.1.dist-info/top_level.txt,sha256=qs1qTnKWImmGi7E0FoJS0OAEOHoVZA9vHRS3Pm6ncAo,5
|
23
|
+
d4rktg-0.3.1.dist-info/RECORD,,
|
File without changes
|
File without changes
|