discord-logging-handler 0.1.0__py2.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.
File without changes
@@ -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,6 @@
1
+ discord_logging_handler/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ discord_logging_handler/handler.py,sha256=rnNOYJMpdQfAAlAXe4ReTYPhjZPB4jakj9W1GlfbzmM,1362
3
+ discord_logging_handler-0.1.0.dist-info/METADATA,sha256=10O5IfLW3Xlcooz6o_8K_dY7DLRhF_SPRpmWu5eDacE,1940
4
+ discord_logging_handler-0.1.0.dist-info/WHEEL,sha256=JNWh1Fm1UdwIQV075glCn4MVuCRs0sotJIq-J6rbxCU,109
5
+ discord_logging_handler-0.1.0.dist-info/top_level.txt,sha256=09nD-D9KaavMF2SPa-tm30eoG4lmcuzUH3Bzma32UPo,24
6
+ discord_logging_handler-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,6 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.9.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py2-none-any
5
+ Tag: py3-none-any
6
+
@@ -0,0 +1 @@
1
+ discord_logging_handler