logmachine 2.2.1__tar.gz → 2.3.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.
- {logmachine-2.2.1 → logmachine-2.3.0}/PKG-INFO +1 -1
- {logmachine-2.2.1 → logmachine-2.3.0}/logmachine/main.py +34 -15
- {logmachine-2.2.1 → logmachine-2.3.0}/logmachine.egg-info/PKG-INFO +1 -1
- {logmachine-2.2.1 → logmachine-2.3.0}/pyproject.toml +2 -2
- {logmachine-2.2.1 → logmachine-2.3.0}/LICENSE +0 -0
- {logmachine-2.2.1 → logmachine-2.3.0}/README.md +0 -0
- {logmachine-2.2.1 → logmachine-2.3.0}/logmachine/__init__.py +0 -0
- {logmachine-2.2.1 → logmachine-2.3.0}/logmachine.egg-info/SOURCES.txt +0 -0
- {logmachine-2.2.1 → logmachine-2.3.0}/logmachine.egg-info/dependency_links.txt +0 -0
- {logmachine-2.2.1 → logmachine-2.3.0}/logmachine.egg-info/top_level.txt +0 -0
- {logmachine-2.2.1 → logmachine-2.3.0}/setup.cfg +0 -0
- {logmachine-2.2.1 → logmachine-2.3.0}/tests/test_core.py +0 -0
|
@@ -1,14 +1,27 @@
|
|
|
1
1
|
import atexit
|
|
2
|
-
import os
|
|
3
|
-
import re
|
|
4
2
|
import json
|
|
5
3
|
import logging
|
|
6
|
-
import
|
|
7
|
-
import socketio
|
|
4
|
+
import os
|
|
8
5
|
import queue
|
|
6
|
+
import re
|
|
7
|
+
import requests
|
|
9
8
|
from logging.handlers import QueueHandler, QueueListener
|
|
10
9
|
|
|
11
10
|
|
|
11
|
+
"""
|
|
12
|
+
We've removed the socketio and websockets dependency from the core of LogMachine to make it more lightweight and avoid forcing users to install it.
|
|
13
|
+
The Logger will use socketio if available in the environment, otherwise it will fall back to HTTP requests for log transport.
|
|
14
|
+
Socketio is generally more efficient for real-time log transport,
|
|
15
|
+
while HTTP can be used as a fallback for environments where socketio is not available or not desired.
|
|
16
|
+
Socketio takes precedence over HTTP if both are available, as it provides a more robust and efficient transport mechanism for real-time logging.
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
try:
|
|
20
|
+
import socketio
|
|
21
|
+
except ImportError:
|
|
22
|
+
pass
|
|
23
|
+
|
|
24
|
+
|
|
12
25
|
def get_login():
|
|
13
26
|
"""
|
|
14
27
|
Get the current user's login name.
|
|
@@ -54,7 +67,7 @@ class HTTPTransporter(logging.StreamHandler):
|
|
|
54
67
|
response = requests.post(
|
|
55
68
|
f"{self.central.get('url', '') + self.central.get('endpoint', '/api/logs')}?room={self.central.get('room', '')}",
|
|
56
69
|
json=log_data,
|
|
57
|
-
headers={
|
|
70
|
+
headers={**self.central.get('headers', {}), 'Content-Type': 'application/json'}
|
|
58
71
|
)
|
|
59
72
|
if response.status_code != 200:
|
|
60
73
|
raise Exception(f"Failed to send log to central: {response.text}")
|
|
@@ -71,21 +84,26 @@ class SocketIOTransporter(logging.StreamHandler):
|
|
|
71
84
|
def __init__(self, *args, **kwargs):
|
|
72
85
|
super().__init__()
|
|
73
86
|
self.parse_log = kwargs.get('log_parser')
|
|
74
|
-
self.central = kwargs.get('central',
|
|
87
|
+
self.central = kwargs.get('central', {})
|
|
75
88
|
self.sio = socketio.Client()
|
|
76
|
-
if self.central:
|
|
77
|
-
|
|
89
|
+
if not self.central:
|
|
90
|
+
raise ValueError("""Central configuration must be provided for SocketIOTransporter.
|
|
91
|
+
Example: {'url': 'http://central-server.com/api/socket.io/', 'room': 'my_organization_name'}
|
|
92
|
+
""")
|
|
93
|
+
try:
|
|
94
|
+
self.sio.connect(self.central.get('url', ''), headers=self.central.get('headers', {}), socketio_path=self.central.get('endpoint', '/api/socket.io/'))
|
|
95
|
+
except Exception as e:
|
|
96
|
+
raise ConnectionError(f"Failed to connect to central server via SocketIO: {e}")
|
|
78
97
|
|
|
79
98
|
def emit(self, record):
|
|
80
99
|
try:
|
|
81
100
|
msg = self.format(record)
|
|
82
101
|
super().emit(record)
|
|
83
|
-
if self.central:
|
|
102
|
+
if self.central and self.sio.connected:
|
|
84
103
|
if not self.central.get('room'):
|
|
85
|
-
raise ValueError("""
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
""")
|
|
104
|
+
raise ValueError("""Central configuration must include 'room' for log transport.
|
|
105
|
+
Example: {'url': 'http://central-server.com/api/socket.io/', 'room': 'my_organization_name'}
|
|
106
|
+
""")
|
|
89
107
|
|
|
90
108
|
log_data = self.parse_log(msg)
|
|
91
109
|
if log_data:
|
|
@@ -172,7 +190,8 @@ class LogMachine(logging.Logger):
|
|
|
172
190
|
if not os.path.exists(os.path.expanduser("~/.cl_username")):
|
|
173
191
|
try:
|
|
174
192
|
login = get_login()
|
|
175
|
-
|
|
193
|
+
username_endpoint = self.central.get('get_username_endpoint', '/api/get_username')
|
|
194
|
+
response = requests.get(f"{self.central.get('url', '')}/{username_endpoint}?base={login}", headers=self.central.get('headers', {}))
|
|
176
195
|
if response.status_code == 200:
|
|
177
196
|
os.environ['CL_USERNAME'] = response.json().get('username') or 'unknown' # Unknown will probably never be reached, but it's a fallback.
|
|
178
197
|
if os.environ.get('CL_USERNAME') != 'unknown':
|
|
@@ -185,7 +204,7 @@ class LogMachine(logging.Logger):
|
|
|
185
204
|
else:
|
|
186
205
|
get_login()
|
|
187
206
|
|
|
188
|
-
if
|
|
207
|
+
if 'socketio' in globals():
|
|
189
208
|
ch = HTTPTransporter(log_parser=self.parse_log, central=self.central)
|
|
190
209
|
else:
|
|
191
210
|
ch = SocketIOTransporter(log_parser=self.parse_log, central=self.central)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "logmachine"
|
|
3
|
-
version = "2.
|
|
3
|
+
version = "2.3.0"
|
|
4
4
|
description = "Collaborative, beautiful logging system for distributed developers"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
requires-python = ">=3.7"
|
|
@@ -22,5 +22,5 @@ Source = "https://github.com/logmachine/python"
|
|
|
22
22
|
Tracker = "https://github.com/logmachine/python/issues"
|
|
23
23
|
|
|
24
24
|
[build-system]
|
|
25
|
-
requires = ["setuptools>=61.0", "
|
|
25
|
+
requires = ["setuptools>=61.0", "requests"]
|
|
26
26
|
build-backend = "setuptools.build_meta"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|