discord-logging-handler 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,78 @@
1
+ Metadata-Version: 2.4
2
+ Name: discord-logging-handler
3
+ Version: 0.1.0
4
+ Summary: A logging handler that sends log messages to discord via webhook.
5
+ Author: Moses White
6
+ Classifier: Programming Language :: Python :: 3
7
+ Classifier: License :: OSI Approved :: MIT License
8
+ Requires-Python: >=3.12
9
+ Description-Content-Type: text/markdown
10
+ Requires-Dist: requests>=2.28
11
+ Dynamic: author
12
+ Dynamic: classifier
13
+ Dynamic: description
14
+ Dynamic: description-content-type
15
+ Dynamic: requires-dist
16
+ Dynamic: requires-python
17
+ Dynamic: summary
18
+
19
+ # Discord Logging Handler
20
+
21
+ A Python logging handler that sends log messages to Discord via webhook with colour coded levels.
22
+
23
+ ## Installation
24
+
25
+ ```bash
26
+ pip install discord-logging-handler
27
+ ```
28
+
29
+ ## Usage
30
+
31
+ ### Django Example
32
+
33
+ settings.py
34
+
35
+ ```bash
36
+ DISCORD_WEBHOOK_URL = os.environ.get('DISCORD_WEBHOOK_URL')
37
+
38
+ LOGGING = {
39
+ 'version': 1,
40
+ 'handlers': {
41
+ 'file': {
42
+ 'level': 'INFO',
43
+ 'class': 'logging.FileHandler',
44
+ 'filename': os.path.join(BASE_DIR, 'logs/app.log'),
45
+ 'formatter': 'verbose',
46
+ },
47
+ 'console': {
48
+ 'class': 'logging.StreamHandler',
49
+ 'formatter': 'simple'
50
+ },
51
+ 'discord': {
52
+ 'level': 'INFO',
53
+ 'class': 'discord_logging_handler.handler.DiscordWebHookHandler',
54
+ 'webhook_url': DISCORD_WEBHOOK_URL
55
+ }
56
+ },
57
+ 'root': {
58
+ 'handlers': ['console', 'file', 'discord'],
59
+ 'level': 'INFO',
60
+ },
61
+ 'loggers': {
62
+ 'django': {
63
+ 'handlers': ['console', 'file'],
64
+ 'level': 'CRITICAL',
65
+ 'propagate': True,
66
+ },
67
+ 'vaultapi': {
68
+ 'handlers': ['console', 'file', 'discord'],
69
+ 'level': 'INFO',
70
+ 'propagate': False,
71
+ },
72
+ },
73
+ }
74
+ ```
75
+
76
+ ### Environment Variable
77
+
78
+ DISCORD_WEBHOOK_URL - Your Discord webhook URL
@@ -0,0 +1,60 @@
1
+ # Discord Logging Handler
2
+
3
+ A Python logging handler that sends log messages to Discord via webhook with colour coded levels.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pip install discord-logging-handler
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ### Django Example
14
+
15
+ settings.py
16
+
17
+ ```bash
18
+ DISCORD_WEBHOOK_URL = os.environ.get('DISCORD_WEBHOOK_URL')
19
+
20
+ LOGGING = {
21
+ 'version': 1,
22
+ 'handlers': {
23
+ 'file': {
24
+ 'level': 'INFO',
25
+ 'class': 'logging.FileHandler',
26
+ 'filename': os.path.join(BASE_DIR, 'logs/app.log'),
27
+ 'formatter': 'verbose',
28
+ },
29
+ 'console': {
30
+ 'class': 'logging.StreamHandler',
31
+ 'formatter': 'simple'
32
+ },
33
+ 'discord': {
34
+ 'level': 'INFO',
35
+ 'class': 'discord_logging_handler.handler.DiscordWebHookHandler',
36
+ 'webhook_url': DISCORD_WEBHOOK_URL
37
+ }
38
+ },
39
+ 'root': {
40
+ 'handlers': ['console', 'file', 'discord'],
41
+ 'level': 'INFO',
42
+ },
43
+ 'loggers': {
44
+ 'django': {
45
+ 'handlers': ['console', 'file'],
46
+ 'level': 'CRITICAL',
47
+ 'propagate': True,
48
+ },
49
+ 'vaultapi': {
50
+ 'handlers': ['console', 'file', 'discord'],
51
+ 'level': 'INFO',
52
+ 'propagate': False,
53
+ },
54
+ },
55
+ }
56
+ ```
57
+
58
+ ### Environment Variable
59
+
60
+ DISCORD_WEBHOOK_URL - Your Discord webhook URL
@@ -0,0 +1,47 @@
1
+ import logging
2
+ import requests
3
+ import json
4
+
5
+ class DiscordWebHookHandler(logging.Handler):
6
+ colour_map = {
7
+ "DEBUG": 8421504,
8
+ "INFO": 3447003,
9
+ "WARNING": 16776960,
10
+ "ERROR": 16711680,
11
+ "CRITICAL": 10038562
12
+ }
13
+
14
+ def __init__(self, webhook_url, level=logging.ERROR, **kwargs):
15
+ super().__init__(level)
16
+ if not webhook_url:
17
+ raise ValueError("webhook_url must be provided")
18
+ self.webhook_url = webhook_url
19
+
20
+ def emit(self, record):
21
+ if self.formatter:
22
+ log_entry = self.format(record)
23
+ else:
24
+ log_entry = record.getMessage()
25
+
26
+ if record.exc_info:
27
+ import traceback
28
+ log_entry += "\n" + "".join(traceback.format_exception(*record.exc_info))
29
+
30
+ colour = self.colour_map.get(record.levelname, 0)
31
+ payload = {
32
+ "embeds": [{
33
+ "title": f"Log ({record.levelname})",
34
+ "description": f"```{log_entry}",
35
+ "color": colour
36
+ }]
37
+ }
38
+ try:
39
+ requests.post(
40
+ self.webhook_url,
41
+ data=json.dumps(payload),
42
+ headers={"Content-Type": "application/json"},
43
+ timeout=5
44
+ )
45
+
46
+ except Exception:
47
+ pass
@@ -0,0 +1,78 @@
1
+ Metadata-Version: 2.4
2
+ Name: discord-logging-handler
3
+ Version: 0.1.0
4
+ Summary: A logging handler that sends log messages to discord via webhook.
5
+ Author: Moses White
6
+ Classifier: Programming Language :: Python :: 3
7
+ Classifier: License :: OSI Approved :: MIT License
8
+ Requires-Python: >=3.12
9
+ Description-Content-Type: text/markdown
10
+ Requires-Dist: requests>=2.28
11
+ Dynamic: author
12
+ Dynamic: classifier
13
+ Dynamic: description
14
+ Dynamic: description-content-type
15
+ Dynamic: requires-dist
16
+ Dynamic: requires-python
17
+ Dynamic: summary
18
+
19
+ # Discord Logging Handler
20
+
21
+ A Python logging handler that sends log messages to Discord via webhook with colour coded levels.
22
+
23
+ ## Installation
24
+
25
+ ```bash
26
+ pip install discord-logging-handler
27
+ ```
28
+
29
+ ## Usage
30
+
31
+ ### Django Example
32
+
33
+ settings.py
34
+
35
+ ```bash
36
+ DISCORD_WEBHOOK_URL = os.environ.get('DISCORD_WEBHOOK_URL')
37
+
38
+ LOGGING = {
39
+ 'version': 1,
40
+ 'handlers': {
41
+ 'file': {
42
+ 'level': 'INFO',
43
+ 'class': 'logging.FileHandler',
44
+ 'filename': os.path.join(BASE_DIR, 'logs/app.log'),
45
+ 'formatter': 'verbose',
46
+ },
47
+ 'console': {
48
+ 'class': 'logging.StreamHandler',
49
+ 'formatter': 'simple'
50
+ },
51
+ 'discord': {
52
+ 'level': 'INFO',
53
+ 'class': 'discord_logging_handler.handler.DiscordWebHookHandler',
54
+ 'webhook_url': DISCORD_WEBHOOK_URL
55
+ }
56
+ },
57
+ 'root': {
58
+ 'handlers': ['console', 'file', 'discord'],
59
+ 'level': 'INFO',
60
+ },
61
+ 'loggers': {
62
+ 'django': {
63
+ 'handlers': ['console', 'file'],
64
+ 'level': 'CRITICAL',
65
+ 'propagate': True,
66
+ },
67
+ 'vaultapi': {
68
+ 'handlers': ['console', 'file', 'discord'],
69
+ 'level': 'INFO',
70
+ 'propagate': False,
71
+ },
72
+ },
73
+ }
74
+ ```
75
+
76
+ ### Environment Variable
77
+
78
+ DISCORD_WEBHOOK_URL - Your Discord webhook URL
@@ -0,0 +1,10 @@
1
+ README.md
2
+ pyproject.toml
3
+ setup.py
4
+ discord_logging_handler/__init__.py
5
+ discord_logging_handler/handler.py
6
+ discord_logging_handler.egg-info/PKG-INFO
7
+ discord_logging_handler.egg-info/SOURCES.txt
8
+ discord_logging_handler.egg-info/dependency_links.txt
9
+ discord_logging_handler.egg-info/requires.txt
10
+ discord_logging_handler.egg-info/top_level.txt
@@ -0,0 +1 @@
1
+ discord_logging_handler
@@ -0,0 +1,3 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61", "wheel"]
3
+ build-backend = "setuptools.build_meta"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,23 @@
1
+ from setuptools import setup, find_packages
2
+
3
+ with open("README.md", "r", encoding="utf-8") as f:
4
+ long_description = f.read()
5
+
6
+ setup(
7
+ name="discord-logging-handler",
8
+ version="0.1.0",
9
+ description="A logging handler that sends log messages to discord via webhook.",
10
+ long_description=long_description,
11
+ long_description_content_type="text/markdown",
12
+ author="Moses White",
13
+ python_requires=">=3.12",
14
+ packages=find_packages(),
15
+ install_requires=[
16
+ "requests>=2.28",
17
+ ],
18
+ classifiers=[
19
+ "Programming Language :: Python :: 3",
20
+ "License :: OSI Approved :: MIT License",
21
+ ],
22
+ include_package_data=True
23
+ )