logdash 0.2.1__tar.gz → 0.2.2__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.
- {logdash-0.2.1/logdash.egg-info → logdash-0.2.2}/PKG-INFO +1 -1
- {logdash-0.2.1 → logdash-0.2.2}/logdash/__init__.py +0 -6
- {logdash-0.2.1 → logdash-0.2.2}/logdash/constants.py +0 -4
- {logdash-0.2.1 → logdash-0.2.2}/logdash/core.py +0 -10
- {logdash-0.2.1 → logdash-0.2.2}/logdash/internal.py +0 -2
- {logdash-0.2.1 → logdash-0.2.2}/logdash/logger.py +19 -41
- {logdash-0.2.1 → logdash-0.2.2}/logdash/metrics/base.py +0 -4
- {logdash-0.2.1 → logdash-0.2.2}/logdash/metrics/factory.py +0 -13
- {logdash-0.2.1 → logdash-0.2.2}/logdash/metrics/impl.py +0 -24
- logdash-0.2.2/logdash/metrics/noop.py +9 -0
- logdash-0.2.2/logdash/sync/base.py +9 -0
- {logdash-0.2.1 → logdash-0.2.2}/logdash/sync/factory.py +0 -13
- {logdash-0.2.1 → logdash-0.2.2}/logdash/sync/http.py +0 -29
- logdash-0.2.2/logdash/sync/noop.py +7 -0
- {logdash-0.2.1 → logdash-0.2.2/logdash.egg-info}/PKG-INFO +1 -1
- {logdash-0.2.1 → logdash-0.2.2}/setup.py +1 -1
- logdash-0.2.1/logdash/metrics/noop.py +0 -32
- logdash-0.2.1/logdash/sync/base.py +0 -21
- logdash-0.2.1/logdash/sync/noop.py +0 -24
- {logdash-0.2.1 → logdash-0.2.2}/LICENSE +0 -0
- {logdash-0.2.1 → logdash-0.2.2}/MANIFEST.in +0 -0
- {logdash-0.2.1 → logdash-0.2.2}/README.md +0 -0
- {logdash-0.2.1 → logdash-0.2.2}/examples/basic_usage.py +0 -0
- {logdash-0.2.1 → logdash-0.2.2}/logdash/metrics/__init__.py +0 -0
- {logdash-0.2.1 → logdash-0.2.2}/logdash/sync/__init__.py +0 -0
- {logdash-0.2.1 → logdash-0.2.2}/logdash.egg-info/SOURCES.txt +0 -0
- {logdash-0.2.1 → logdash-0.2.2}/logdash.egg-info/dependency_links.txt +0 -0
- {logdash-0.2.1 → logdash-0.2.2}/logdash.egg-info/requires.txt +0 -0
- {logdash-0.2.1 → logdash-0.2.2}/logdash.egg-info/top_level.txt +0 -0
- {logdash-0.2.1 → logdash-0.2.2}/setup.cfg +0 -0
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
"""Constants used throughout the logdash SDK."""
|
|
2
|
-
|
|
3
1
|
from enum import Enum
|
|
4
2
|
|
|
5
3
|
|
|
6
4
|
class LogLevel(str, Enum):
|
|
7
|
-
"""Log levels supported by logdash."""
|
|
8
5
|
ERROR = "error"
|
|
9
6
|
WARN = "warning"
|
|
10
7
|
INFO = "info"
|
|
@@ -15,7 +12,6 @@ class LogLevel(str, Enum):
|
|
|
15
12
|
|
|
16
13
|
|
|
17
14
|
class MetricOperation(str, Enum):
|
|
18
|
-
"""Metric operations supported by logdash."""
|
|
19
15
|
SET = "set"
|
|
20
16
|
CHANGE = "change"
|
|
21
17
|
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
"""Core functionality for the logdash SDK."""
|
|
2
|
-
|
|
3
1
|
from datetime import datetime
|
|
4
2
|
from typing import Dict, Optional, Any
|
|
5
3
|
|
|
@@ -12,14 +10,6 @@ from logdash.constants import LogLevel
|
|
|
12
10
|
|
|
13
11
|
class logdash:
|
|
14
12
|
def __init__(self, api_key: Optional[str] = None, host: str = "https://api.logdash.io", verbose: bool = False):
|
|
15
|
-
"""
|
|
16
|
-
Initialize a new logdash instance.
|
|
17
|
-
|
|
18
|
-
Args:
|
|
19
|
-
api_key: Your logdash API key
|
|
20
|
-
host: logdash API host (defaults to https://api.logdash.io)
|
|
21
|
-
verbose: Enable verbose mode
|
|
22
|
-
"""
|
|
23
13
|
# Ensure we have an API key (or empty string)
|
|
24
14
|
self._api_key = api_key or ""
|
|
25
15
|
self._host = host
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
"""Logger implementation for logdash."""
|
|
2
|
-
|
|
3
1
|
from datetime import datetime
|
|
2
|
+
import json
|
|
4
3
|
from typing import Any, Callable, Optional, Tuple
|
|
5
4
|
|
|
6
5
|
from colorama import init # For Windows compatibility
|
|
@@ -9,44 +8,39 @@ from logdash.constants import LogLevel, LOG_LEVEL_COLORS
|
|
|
9
8
|
# Initialize colorama for cross-platform terminal colors
|
|
10
9
|
init()
|
|
11
10
|
|
|
12
|
-
|
|
13
11
|
class Logger:
|
|
14
|
-
"""
|
|
15
|
-
A flexible logger for terminal output and remote logging.
|
|
16
|
-
|
|
17
|
-
The Logger provides methods for different log levels and can
|
|
18
|
-
both print locally and send logs to a remote service.
|
|
19
|
-
"""
|
|
20
|
-
|
|
21
12
|
def __init__(
|
|
22
13
|
self,
|
|
23
14
|
log_method: Callable = print,
|
|
24
15
|
prefix: Optional[Callable[[LogLevel], str]] = None,
|
|
25
16
|
on_log: Optional[Callable[[LogLevel, str], None]] = None,
|
|
26
17
|
):
|
|
27
|
-
"""
|
|
28
|
-
Initialize a new Logger instance.
|
|
29
|
-
|
|
30
|
-
Args:
|
|
31
|
-
log_method: Function to use for local logging (default: print)
|
|
32
|
-
prefix: Optional function to generate log level prefix
|
|
33
|
-
on_log: Optional callback for when logs are generated
|
|
34
|
-
"""
|
|
35
18
|
self.log_method = log_method
|
|
36
19
|
self.prefix = prefix or (lambda level: f"{level.value.upper()} ")
|
|
37
20
|
self.on_log = on_log
|
|
38
21
|
|
|
22
|
+
def _format_item(self, item: Any) -> str:
|
|
23
|
+
"""Format an item for logging, converting to JSON if possible."""
|
|
24
|
+
try:
|
|
25
|
+
# Check if the item is a dict, list, or other JSON-serializable object
|
|
26
|
+
if isinstance(item, (dict, list)) or hasattr(item, "__dict__"):
|
|
27
|
+
return json.dumps(item, default=lambda o: o.__dict__ if hasattr(o, "__dict__") else str(o))
|
|
28
|
+
return str(item)
|
|
29
|
+
except (TypeError, ValueError):
|
|
30
|
+
# Fallback to string representation if JSON serialization fails
|
|
31
|
+
return str(item)
|
|
32
|
+
|
|
39
33
|
def error(self, *data: Any) -> None:
|
|
40
34
|
"""Log an error message."""
|
|
41
|
-
self._log(LogLevel.ERROR, " ".join(
|
|
35
|
+
self._log(LogLevel.ERROR, " ".join(self._format_item(item) for item in data))
|
|
42
36
|
|
|
43
37
|
def warn(self, *data: Any) -> None:
|
|
44
38
|
"""Log a warning message."""
|
|
45
|
-
self._log(LogLevel.WARN, " ".join(
|
|
39
|
+
self._log(LogLevel.WARN, " ".join(self._format_item(item) for item in data))
|
|
46
40
|
|
|
47
41
|
def info(self, *data: Any) -> None:
|
|
48
42
|
"""Log an info message."""
|
|
49
|
-
self._log(LogLevel.INFO, " ".join(
|
|
43
|
+
self._log(LogLevel.INFO, " ".join(self._format_item(item) for item in data))
|
|
50
44
|
|
|
51
45
|
def log(self, *data: Any) -> None:
|
|
52
46
|
"""Alias for info()."""
|
|
@@ -54,41 +48,25 @@ class Logger:
|
|
|
54
48
|
|
|
55
49
|
def http(self, *data: Any) -> None:
|
|
56
50
|
"""Log an HTTP-related message."""
|
|
57
|
-
self._log(LogLevel.HTTP, " ".join(
|
|
51
|
+
self._log(LogLevel.HTTP, " ".join(self._format_item(item) for item in data))
|
|
58
52
|
|
|
59
53
|
def verbose(self, *data: Any) -> None:
|
|
60
54
|
"""Log a verbose message."""
|
|
61
|
-
self._log(LogLevel.VERBOSE, " ".join(
|
|
55
|
+
self._log(LogLevel.VERBOSE, " ".join(self._format_item(item) for item in data))
|
|
62
56
|
|
|
63
57
|
def debug(self, *data: Any) -> None:
|
|
64
58
|
"""Log a debug message."""
|
|
65
|
-
self._log(LogLevel.DEBUG, " ".join(
|
|
59
|
+
self._log(LogLevel.DEBUG, " ".join(self._format_item(item) for item in data))
|
|
66
60
|
|
|
67
61
|
def silly(self, *data: Any) -> None:
|
|
68
62
|
"""Log a silly message (lowest priority)."""
|
|
69
|
-
self._log(LogLevel.SILLY, " ".join(
|
|
63
|
+
self._log(LogLevel.SILLY, " ".join(self._format_item(item) for item in data))
|
|
70
64
|
|
|
71
65
|
def _rgb_to_ansi(self, rgb: Tuple[int, int, int]) -> str:
|
|
72
|
-
"""
|
|
73
|
-
Convert RGB values to ANSI color escape sequence.
|
|
74
|
-
|
|
75
|
-
Args:
|
|
76
|
-
rgb: Tuple of (r, g, b) values
|
|
77
|
-
|
|
78
|
-
Returns:
|
|
79
|
-
ANSI color code string
|
|
80
|
-
"""
|
|
81
66
|
r, g, b = rgb
|
|
82
67
|
return f"\033[38;2;{r};{g};{b}m"
|
|
83
68
|
|
|
84
69
|
def _log(self, level: LogLevel, message: str) -> None:
|
|
85
|
-
"""
|
|
86
|
-
Internal method to format and output a log message.
|
|
87
|
-
|
|
88
|
-
Args:
|
|
89
|
-
level: The log level
|
|
90
|
-
message: The message to log
|
|
91
|
-
"""
|
|
92
70
|
# Get RGB values and convert to ANSI color
|
|
93
71
|
rgb_color = LOG_LEVEL_COLORS[level]
|
|
94
72
|
color_code = self._rgb_to_ansi(rgb_color)
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
"""Factory function for creating metrics instances."""
|
|
2
|
-
|
|
3
1
|
from logdash.metrics.base import BaseMetrics
|
|
4
2
|
from logdash.metrics.impl import Metrics
|
|
5
3
|
from logdash.metrics.noop import NoopMetrics
|
|
@@ -7,17 +5,6 @@ from logdash.internal import internal_logger
|
|
|
7
5
|
|
|
8
6
|
|
|
9
7
|
def create_metrics(api_key: str, host: str, verbose: bool = False) -> BaseMetrics:
|
|
10
|
-
"""
|
|
11
|
-
Create a metrics instance based on the provided parameters.
|
|
12
|
-
|
|
13
|
-
Args:
|
|
14
|
-
api_key: logdash API key
|
|
15
|
-
host: logdash API host
|
|
16
|
-
verbose: Enable verbose mode
|
|
17
|
-
|
|
18
|
-
Returns:
|
|
19
|
-
A BaseMetrics instance
|
|
20
|
-
"""
|
|
21
8
|
if not api_key:
|
|
22
9
|
if verbose:
|
|
23
10
|
internal_logger.warn("No API key provided, using NoopMetrics")
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
"""HTTP-based metrics implementation."""
|
|
2
|
-
|
|
3
1
|
import requests
|
|
4
2
|
|
|
5
3
|
from logdash.metrics.base import BaseMetrics
|
|
@@ -8,21 +6,7 @@ from logdash.internal import internal_logger
|
|
|
8
6
|
|
|
9
7
|
|
|
10
8
|
class Metrics(BaseMetrics):
|
|
11
|
-
"""
|
|
12
|
-
HTTP-based metrics implementation.
|
|
13
|
-
|
|
14
|
-
Sends metrics to the logdash API via HTTP.
|
|
15
|
-
"""
|
|
16
|
-
|
|
17
9
|
def __init__(self, api_key: str, host: str, verbose: bool = False):
|
|
18
|
-
"""
|
|
19
|
-
Initialize a metrics instance.
|
|
20
|
-
|
|
21
|
-
Args:
|
|
22
|
-
api_key: logdash API key
|
|
23
|
-
host: logdash API host
|
|
24
|
-
verbose: Enable verbose mode
|
|
25
|
-
"""
|
|
26
10
|
self.api_key = api_key
|
|
27
11
|
self.host = host
|
|
28
12
|
self.verbose = verbose
|
|
@@ -54,14 +38,6 @@ class Metrics(BaseMetrics):
|
|
|
54
38
|
self._send_metric(name, value, MetricOperation.CHANGE)
|
|
55
39
|
|
|
56
40
|
def _send_metric(self, name: str, value: float, operation: MetricOperation) -> None:
|
|
57
|
-
"""
|
|
58
|
-
Send a metric to the logdash API.
|
|
59
|
-
|
|
60
|
-
Args:
|
|
61
|
-
name: The metric name
|
|
62
|
-
value: The metric value
|
|
63
|
-
operation: The operation to perform
|
|
64
|
-
"""
|
|
65
41
|
# Skip if no API key is provided
|
|
66
42
|
if not self.api_key:
|
|
67
43
|
return
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
"""Factory function for creating log sync instances."""
|
|
2
|
-
|
|
3
1
|
from logdash.sync.base import LogSync
|
|
4
2
|
from logdash.sync.http import HttpLogSync
|
|
5
3
|
from logdash.sync.noop import NoopLogSync
|
|
@@ -7,17 +5,6 @@ from logdash.internal import internal_logger
|
|
|
7
5
|
|
|
8
6
|
|
|
9
7
|
def create_log_sync(api_key: str, host: str, verbose: bool = False) -> LogSync:
|
|
10
|
-
"""
|
|
11
|
-
Create a log sync instance based on the provided parameters.
|
|
12
|
-
|
|
13
|
-
Args:
|
|
14
|
-
api_key: logdash API key
|
|
15
|
-
host: logdash API host
|
|
16
|
-
verbose: Enable verbose mode
|
|
17
|
-
|
|
18
|
-
Returns:
|
|
19
|
-
A LogSync instance
|
|
20
|
-
"""
|
|
21
8
|
if not api_key:
|
|
22
9
|
if verbose:
|
|
23
10
|
internal_logger.warn("No API key provided, using NoopLogSync")
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
"""HTTP-based log synchronization implementation."""
|
|
2
|
-
|
|
3
1
|
import requests
|
|
4
2
|
|
|
5
3
|
from logdash.sync.base import LogSync
|
|
@@ -7,41 +5,14 @@ from logdash.constants import LogLevel
|
|
|
7
5
|
|
|
8
6
|
|
|
9
7
|
class HttpLogSync(LogSync):
|
|
10
|
-
"""
|
|
11
|
-
HTTP-based log synchronization implementation.
|
|
12
|
-
|
|
13
|
-
Sends logs to the logdash API via HTTP.
|
|
14
|
-
"""
|
|
15
8
|
|
|
16
9
|
def __init__(self, api_key: str, host: str, verbose: bool = False):
|
|
17
|
-
"""
|
|
18
|
-
Initialize an HTTP log sync instance.
|
|
19
|
-
|
|
20
|
-
Args:
|
|
21
|
-
api_key: logdash API key
|
|
22
|
-
host: logdash API host
|
|
23
|
-
verbose: Enable verbose mode
|
|
24
|
-
"""
|
|
25
10
|
self.api_key = api_key
|
|
26
11
|
self.host = host
|
|
27
12
|
self.verbose = verbose
|
|
28
13
|
self.sequence_number = 0
|
|
29
14
|
|
|
30
15
|
def send(self, message: str, level: LogLevel, created_at: str) -> None:
|
|
31
|
-
"""
|
|
32
|
-
Send a log message to the logdash API.
|
|
33
|
-
|
|
34
|
-
Args:
|
|
35
|
-
message: The log message content
|
|
36
|
-
level: The log level
|
|
37
|
-
created_at: ISO-formatted timestamp when the log was created
|
|
38
|
-
|
|
39
|
-
Todo:
|
|
40
|
-
- Implement queue for offline support
|
|
41
|
-
- Add retry mechanism
|
|
42
|
-
- Implement batching for better performance
|
|
43
|
-
"""
|
|
44
|
-
# Skip if no API key is provided
|
|
45
16
|
if not self.api_key:
|
|
46
17
|
return
|
|
47
18
|
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"""No-operation metrics implementation."""
|
|
2
|
-
|
|
3
|
-
from logdash.metrics.base import BaseMetrics
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
class NoopMetrics(BaseMetrics):
|
|
7
|
-
"""
|
|
8
|
-
No-operation metrics implementation.
|
|
9
|
-
|
|
10
|
-
This implementation does nothing when metrics are set or mutated.
|
|
11
|
-
Useful for testing or when no remote metrics collection is needed.
|
|
12
|
-
"""
|
|
13
|
-
|
|
14
|
-
def set(self, name: str, value: float) -> None:
|
|
15
|
-
"""
|
|
16
|
-
Do nothing with the metric.
|
|
17
|
-
|
|
18
|
-
Args:
|
|
19
|
-
name: The metric name
|
|
20
|
-
value: The value to set
|
|
21
|
-
"""
|
|
22
|
-
pass
|
|
23
|
-
|
|
24
|
-
def mutate(self, name: str, value: float) -> None:
|
|
25
|
-
"""
|
|
26
|
-
Do nothing with the metric.
|
|
27
|
-
|
|
28
|
-
Args:
|
|
29
|
-
name: The metric name
|
|
30
|
-
value: The amount to change by
|
|
31
|
-
"""
|
|
32
|
-
pass
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"""Base class for log synchronization implementations."""
|
|
2
|
-
|
|
3
|
-
from abc import ABC, abstractmethod
|
|
4
|
-
|
|
5
|
-
from logdash.constants import LogLevel
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
class LogSync(ABC):
|
|
9
|
-
"""Abstract base class for log synchronization implementations."""
|
|
10
|
-
|
|
11
|
-
@abstractmethod
|
|
12
|
-
def send(self, message: str, level: LogLevel, created_at: str) -> None:
|
|
13
|
-
"""
|
|
14
|
-
Send a log message to the remote service.
|
|
15
|
-
|
|
16
|
-
Args:
|
|
17
|
-
message: The log message content
|
|
18
|
-
level: The log level
|
|
19
|
-
created_at: ISO-formatted timestamp when the log was created
|
|
20
|
-
"""
|
|
21
|
-
pass
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"""No-operation log synchronization implementation."""
|
|
2
|
-
|
|
3
|
-
from logdash.sync.base import LogSync
|
|
4
|
-
from logdash.constants import LogLevel
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
class NoopLogSync(LogSync):
|
|
8
|
-
"""
|
|
9
|
-
No-operation log synchronization implementation.
|
|
10
|
-
|
|
11
|
-
This implementation does nothing when logs are sent to it.
|
|
12
|
-
Useful for testing or when no remote logging is needed.
|
|
13
|
-
"""
|
|
14
|
-
|
|
15
|
-
def send(self, message: str, level: LogLevel, created_at: str) -> None:
|
|
16
|
-
"""
|
|
17
|
-
Do nothing with the log message.
|
|
18
|
-
|
|
19
|
-
Args:
|
|
20
|
-
message: The log message content
|
|
21
|
-
level: The log level
|
|
22
|
-
created_at: ISO-formatted timestamp when the log was created
|
|
23
|
-
"""
|
|
24
|
-
pass
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|