You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
> STATUS: In development. The API is not yet stable.
12
13
13
14
## Description
14
15
@@ -18,7 +19,7 @@ STATUS: In development
18
19
19
20
-**Asynchronous Processing**: Log events are queued and dispatched in a dedicated background thread, ensuring your application's main execution flow remains non-blocking and highly responsive.
20
21
21
-
-**Efficient Request Batching**: To optimize network throughput and reduce overhead on your VictoriaLogs server, multiple log events are automatically combined into single-request batches.
22
+
-**Efficient Request Batching**: To optimize network throughput and reduce overhead on your VictoriaLogs server, multiple log events are combined into chunks per request.
22
23
23
24
-**Rich Exception Handling**: Automatically captures and flattens stack traces. Log messages include both the exception name and the full traceback as searchable fields.
Then it can be used like any other logging handler to configure a logger.
38
39
39
-
## Usage
40
+
## Quick start
40
41
41
-
Please see the directory `/examples` for examples on how to use the handler.
42
+
> [!NOTE]
43
+
> The script assumes that there is a VictoriaLogs server running
44
+
> on the same system at the default URL: `http://localhost:9428`
45
+
46
+
Here is a quick example on how to use the handler in your Python script:
47
+
48
+
```python
49
+
import atexit
50
+
import logging
51
+
52
+
from vlogs_handler import VictoriaLogsHandler
53
+
54
+
# Create a custom logger with INFO level
55
+
logger = logging.getLogger(__name__)
56
+
logger.setLevel(logging.INFO)
57
+
58
+
# Add a handler for VictoriaLogs
59
+
vlogs_handler = VictoriaLogsHandler()
60
+
vlogs_handler.setLevel(logging.DEBUG)
61
+
logger.addHandler(vlogs_handler)
62
+
63
+
# Make sure to flush logs before exiting
64
+
atexit.register(logging.shutdown)
65
+
66
+
# Log example
67
+
logger.info("This is an info message")
68
+
```
69
+
70
+
Please see the directory `/examples` for additional examples on how to use the handler.
42
71
43
72
## Technical details
44
73
45
74
This section documents technical details of the solution.
46
75
76
+
### Technical process
77
+
78
+
The vlogs handler works as follows:
79
+
80
+
1. When a a log event is received, it is converted into JSON and stored in the buffer
81
+
2. At an interval (e.g. 5 second) or when a threshold is reached (e.g. 125 logs) a background worker starts the process of submitting logs from the buffer to the log server
82
+
3. Logs are combined into chunks (e.g. 1.000 logs per request) and then submitted to the log server using vlog's the JSON Stream API
83
+
4. In case submission fails (e.g. the log server is down) the logs will be stored back to the buffer for later retry
84
+
5. In case the buffer is full new logs will be discarded.
85
+
6. When the service shuts down, logs remaining in the buffer are transferred to the log server.
86
+
47
87
### LogRecord fields
48
88
49
89
The following fields will be transferred for each log event. They are derived from Python's [LogRecord](https://docs.python.org/3/library/logging.html#logrecord-objects):
0 commit comments