d4rklogger 0.1.0__tar.gz

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,45 @@
1
+ Metadata-Version: 2.4
2
+ Name: d4rklogger
3
+ Version: 0.1.0
4
+ Summary: Simple timezone-aware logging helpers with rotating file output.
5
+ Author: D4rk-TG
6
+ Keywords: logging,logger,timezone
7
+ Classifier: Programming Language :: Python :: 3
8
+ Classifier: Programming Language :: Python :: 3 :: Only
9
+ Classifier: Operating System :: OS Independent
10
+ Classifier: Topic :: System :: Logging
11
+ Requires-Python: >=3.8
12
+ Description-Content-Type: text/markdown
13
+ Provides-Extra: colors
14
+ Requires-Dist: colorama>=0.4.6; extra == "colors"
15
+
16
+ # d4rklogger
17
+
18
+ Lightweight timezone-aware logger setup with:
19
+
20
+ - rotating daily log files
21
+ - optional colored console output
22
+ - configurable timezone offset through `TIME_ZONE`
23
+
24
+ ## Install
25
+
26
+ ```bash
27
+ pip install d4rklogger
28
+ ```
29
+
30
+ Optional color support:
31
+
32
+ ```bash
33
+ pip install ".[colors]"
34
+ ```
35
+
36
+ ## Usage
37
+
38
+ ```python
39
+ from log import setup_logger
40
+
41
+ log = setup_logger("app")
42
+ log.info("hello")
43
+ ```
44
+
45
+ Set the timezone offset with an environment variable such as `TIME_ZONE=05:30` or `TIME_ZONE=-04:00`.
@@ -0,0 +1,30 @@
1
+ # d4rklogger
2
+
3
+ Lightweight timezone-aware logger setup with:
4
+
5
+ - rotating daily log files
6
+ - optional colored console output
7
+ - configurable timezone offset through `TIME_ZONE`
8
+
9
+ ## Install
10
+
11
+ ```bash
12
+ pip install d4rklogger
13
+ ```
14
+
15
+ Optional color support:
16
+
17
+ ```bash
18
+ pip install ".[colors]"
19
+ ```
20
+
21
+ ## Usage
22
+
23
+ ```python
24
+ from log import setup_logger
25
+
26
+ log = setup_logger("app")
27
+ log.info("hello")
28
+ ```
29
+
30
+ Set the timezone offset with an environment variable such as `TIME_ZONE=05:30` or `TIME_ZONE=-04:00`.
@@ -0,0 +1,45 @@
1
+ Metadata-Version: 2.4
2
+ Name: d4rklogger
3
+ Version: 0.1.0
4
+ Summary: Simple timezone-aware logging helpers with rotating file output.
5
+ Author: D4rk-TG
6
+ Keywords: logging,logger,timezone
7
+ Classifier: Programming Language :: Python :: 3
8
+ Classifier: Programming Language :: Python :: 3 :: Only
9
+ Classifier: Operating System :: OS Independent
10
+ Classifier: Topic :: System :: Logging
11
+ Requires-Python: >=3.8
12
+ Description-Content-Type: text/markdown
13
+ Provides-Extra: colors
14
+ Requires-Dist: colorama>=0.4.6; extra == "colors"
15
+
16
+ # d4rklogger
17
+
18
+ Lightweight timezone-aware logger setup with:
19
+
20
+ - rotating daily log files
21
+ - optional colored console output
22
+ - configurable timezone offset through `TIME_ZONE`
23
+
24
+ ## Install
25
+
26
+ ```bash
27
+ pip install d4rklogger
28
+ ```
29
+
30
+ Optional color support:
31
+
32
+ ```bash
33
+ pip install ".[colors]"
34
+ ```
35
+
36
+ ## Usage
37
+
38
+ ```python
39
+ from log import setup_logger
40
+
41
+ log = setup_logger("app")
42
+ log.info("hello")
43
+ ```
44
+
45
+ Set the timezone offset with an environment variable such as `TIME_ZONE=05:30` or `TIME_ZONE=-04:00`.
@@ -0,0 +1,11 @@
1
+ README.md
2
+ pyproject.toml
3
+ d4rklogger.egg-info/PKG-INFO
4
+ d4rklogger.egg-info/SOURCES.txt
5
+ d4rklogger.egg-info/dependency_links.txt
6
+ d4rklogger.egg-info/requires.txt
7
+ d4rklogger.egg-info/top_level.txt
8
+ log/__init__.py
9
+ log/_logger.py
10
+ logger/__init__.py
11
+ logger/_logger.py
@@ -0,0 +1,3 @@
1
+
2
+ [colors]
3
+ colorama>=0.4.6
@@ -0,0 +1,3 @@
1
+ log
2
+ logger
3
+ logs
@@ -0,0 +1,8 @@
1
+ from ._logger import TZ, TimeZoneFormatter, get_timezone_offset, setup_logger
2
+
3
+ __all__ = [
4
+ "TZ",
5
+ "TimeZoneFormatter",
6
+ "get_timezone_offset",
7
+ "setup_logger",
8
+ ]
@@ -0,0 +1,111 @@
1
+ import logging
2
+ import os
3
+ import sys
4
+
5
+ from datetime import datetime, timedelta, timezone
6
+ from logging.handlers import TimedRotatingFileHandler
7
+
8
+ try:
9
+ import colorama
10
+
11
+ colorama.init(strip=False, autoreset=True)
12
+ COLORAMA_AVAILABLE = True
13
+ except ImportError:
14
+ COLORAMA_AVAILABLE = False
15
+
16
+
17
+ def get_timezone_offset(time_zone: str = "00:00") -> timezone:
18
+ if time_zone:
19
+ try:
20
+ hours, minutes = time_zone.split(":")
21
+ if hours.startswith("-"):
22
+ return timezone(timedelta(hours=-int(hours), minutes=-int(minutes)))
23
+ return timezone(timedelta(hours=int(hours), minutes=int(minutes)))
24
+ except ValueError as exc:
25
+ raise ValueError(f"Invalid TIME_ZONE format: {time_zone}") from exc
26
+ return timezone(timedelta(hours=0))
27
+
28
+
29
+ TZ = get_timezone_offset(os.getenv("TIME_ZONE", "05:30"))
30
+
31
+
32
+ class TimeZoneFormatter(logging.Formatter):
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
+ "TIME": "\033[93m",
38
+ "NAME": "\033[36m",
39
+ "FUNC": "\033[34m",
40
+ "LEVEL": {
41
+ logging.DEBUG: "\033[37m",
42
+ logging.INFO: "\033[32m",
43
+ logging.WARNING: "\033[33m",
44
+ logging.ERROR: "\033[31m",
45
+ logging.CRITICAL: "\033[41m",
46
+ },
47
+ }
48
+ self.RESET = "\033[0m"
49
+
50
+ def formatTime(self, record, datefmt=None):
51
+ dt = datetime.fromtimestamp(record.created, tz=timezone.utc)
52
+ time_zone_time = dt.astimezone(TZ)
53
+ if datefmt:
54
+ return time_zone_time.strftime(datefmt)
55
+ return time_zone_time.strftime("%Y-%m-%d %H:%M:%S %z")
56
+
57
+ def format(self, record):
58
+ if not self.use_colors:
59
+ return super().format(record)
60
+
61
+ time_str = f"{self.COLORS['TIME']}{self.formatTime(record, self.datefmt)}{self.RESET}"
62
+ name_str = f"{self.COLORS['NAME']}{record.name}{self.RESET}"
63
+ func_str = f"{self.COLORS['FUNC']}{record.funcName}:{record.lineno}{self.RESET}"
64
+ level_color = self.COLORS["LEVEL"].get(record.levelno, "")
65
+ level_str = f"{level_color}{record.levelname}{self.RESET}"
66
+ msg_str = f"{level_color}{record.getMessage()}{self.RESET}"
67
+
68
+ return f"{time_str} - {name_str} - {func_str} - {level_str} - {msg_str}"
69
+
70
+
71
+ def setup_logger(name=__name__, log_level=logging.INFO):
72
+ log_dir = "logs"
73
+ if not os.path.exists(log_dir):
74
+ os.makedirs(log_dir)
75
+
76
+ logger = logging.getLogger(name)
77
+ logger.setLevel(log_level)
78
+
79
+ if logger.handlers:
80
+ return logger
81
+
82
+ time_zone_now = datetime.now(TZ)
83
+
84
+ file_handler = TimedRotatingFileHandler(
85
+ filename=os.path.join(log_dir, f"log-{time_zone_now.strftime('%Y-%m-%d')}.txt"),
86
+ when="midnight",
87
+ interval=1,
88
+ backupCount=30,
89
+ )
90
+ file_handler.setLevel(log_level)
91
+
92
+ console_handler = logging.StreamHandler()
93
+ console_handler.setLevel(log_level)
94
+ use_colors = sys.stdout.isatty() and COLORAMA_AVAILABLE
95
+ plain_formatter = TimeZoneFormatter(
96
+ "%(asctime)s - %(name)s - %(funcName)s:%(lineno)d - %(levelname)s - %(message)s",
97
+ datefmt="%Y-%m-%d %H:%M:%S",
98
+ use_colors=False,
99
+ )
100
+ formatter = TimeZoneFormatter(
101
+ "%(asctime)s - %(name)s - %(funcName)s:%(lineno)d - %(levelname)s - %(message)s",
102
+ datefmt="%Y-%m-%d %H:%M:%S",
103
+ use_colors=use_colors,
104
+ )
105
+
106
+ file_handler.setFormatter(plain_formatter)
107
+ console_handler.setFormatter(formatter)
108
+ logger.addHandler(file_handler)
109
+ logger.addHandler(console_handler)
110
+ logger.propagate = False
111
+ return logger
@@ -0,0 +1,8 @@
1
+ from log import TZ, TimeZoneFormatter, get_timezone_offset, setup_logger
2
+
3
+ __all__ = [
4
+ "TZ",
5
+ "TimeZoneFormatter",
6
+ "get_timezone_offset",
7
+ "setup_logger",
8
+ ]
@@ -0,0 +1,8 @@
1
+ from log._logger import TZ, TimeZoneFormatter, get_timezone_offset, setup_logger
2
+
3
+ __all__ = [
4
+ "TZ",
5
+ "TimeZoneFormatter",
6
+ "get_timezone_offset",
7
+ "setup_logger",
8
+ ]
@@ -0,0 +1,29 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "d4rklogger"
7
+ version = "0.1.0"
8
+ description = "Simple timezone-aware logging helpers with rotating file output."
9
+ readme = "README.md"
10
+ requires-python = ">=3.8"
11
+ authors = [
12
+ { name = "D4rk-TG" }
13
+ ]
14
+ keywords = ["logging", "logger", "timezone"]
15
+ classifiers = [
16
+ "Programming Language :: Python :: 3",
17
+ "Programming Language :: Python :: 3 :: Only",
18
+ "Operating System :: OS Independent",
19
+ "Topic :: System :: Logging"
20
+ ]
21
+
22
+ [project.optional-dependencies]
23
+ colors = ["colorama>=0.4.6"]
24
+
25
+ [tool.setuptools]
26
+ include-package-data = false
27
+
28
+ [tool.setuptools.packages.find]
29
+ include = ["log*", "logger*"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+