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 may still change.
13
-
14
11
## Description
15
12
16
13
**victorialogs-handler** is a high-performance Python log handler tailored for [VictoriaLogs](https://victoriametrics.com/products/victorialogs/). It integrates seamlessly with Python’s native logging module, allowing you to stream log events to a VictoriaLogs instance with minimal configuration.
Copy file name to clipboardExpand all lines: src/vlogs_handler/technical.md
+66-18Lines changed: 66 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,32 +1,80 @@
1
-
# Technical overview
1
+
# Technical documentation
2
2
3
-
This section gives a technical overview of how the vlogs handler works.
3
+
This section describes how the handler works and how it can be configured.
4
4
5
5
## Process Flow
6
6
7
7
The high-level process flow of the vlogs handler is as follows:
8
8
9
-
1. When a a log event is received, it is converted into JSON and stored
10
-
in the buffer
11
-
1. At the tick of an interval (e.g. 5 seconds) or when a threshold is reached
12
-
(e.g. 125 logs) a background worker starts the process of submitting logs
13
-
from the buffer to the log server
14
-
1. Logs are combined into chunks (e.g. 1.000 logs per request)
15
-
and then submitted to the log server using vlog's the JSON Stream API
9
+
- When a log event is received, it is converted into JSON and stored in the buffer.
10
+
- When the logs are flushed, they are transferred to the log server by a background worker.
11
+
- The flushing of the buffer is triggered when the `flush_interval` expires (e.g. every 5 seconds) or when more then `batch_size` logs (e.g. 125) have been received.
12
+
- Logs are combined into chunks defined by `chunk_size` (e.g. 1.000 logs per request) and then submitted to the log server using the JSON Stream API.
16
13
17
14
## Failure behavior
18
15
19
16
The failure behavior of the handler in key scenarios is as follows:
20
17
21
-
- In case the submission to the log server fails
22
-
(e.g. the server is temporarily down) the logs will be stored
23
-
in the buffer for later retry
24
-
- If the buffer is full, new log events will be discarded
25
-
and raise a exceptions (depending on logging configuration)
26
-
- The handler will make a final attempt to submit remaining logs during shutdown.
27
-
If that fails those logs will written to stderr.
18
+
- In case the submission to the log server fails (e.g. the server is temporarily down) the logs will be stored in the buffer for later retry.
19
+
- If the buffer is full, new log events will be discarded and raise a exceptions (depending on logging configuration).
20
+
- The handler will make a final attempt to submit remaining logs during shutdown. If that fails those logs will written to stderr.
28
21
29
-
## LogRecord fields
22
+
## Configuration
23
+
24
+
This section describes how the handler and it's logger can be configured.
25
+
26
+
### Handler configuration
27
+
28
+
> [!TIP]
29
+
> The handler comes pre-configured with sensible defaults and often does not need to be configured.
30
+
31
+
The handler can be configured through keyword argument of the handler's constructor.
32
+
All arguments are optional and will be set to sensible defaults when not provided.
33
+
34
+
For example the size of the log buffer can be configured by setting `buffer_size`:
For a full description of all arguments please see `VictoriaLogsHandler`.
41
+
42
+
### Handler logging
43
+
44
+
The vlogs handler has it's own logger and which can be found under the name `vlogs_handler`.
45
+
It will log issues related to transferring logs to the vlogs server.
46
+
47
+
For example this will attach a console handler to the logger with warning level:
48
+
49
+
```python
50
+
console_handler = logging.StreamHandler()
51
+
console_handler.setLevel(logging.DEBUG)
52
+
vlogs_logger = logging.getLogger("vlogs_handler")
53
+
vlogs_handler.setLevel(logging.WARNING)
54
+
vlogs_logger.addHandler(console_handler)
55
+
```
56
+
57
+
> [!NOTE]
58
+
> A vlogs handler instance can not be attached to this logger, as this would create an infinite loop.
59
+
60
+
## Limitations
61
+
62
+
The handler was designed for a specific scenario:
63
+
64
+
- Transfer logs from a Django server to a VictoriaLogs instance running on the same server
65
+
- Our focus is on applications logs over server logs (i.e. logs from Django apps over logs from the Django server itself)
66
+
- The handler should be easy to install and use
67
+
68
+
Our design choices result in a few limitations:
69
+
70
+
- The buffer is kept in memory, which means that there is a risk that some logs are lost when the Django server itself has a failure. Because of that limitation we recommend not to rely on the vlogs handler alone, but to always use a log file as backup.
71
+
- The handler does not implement HTTP authentication or backoff and retry logic for HTTP requests. It is therefore currently not suitable to be used with a remote VictoriaLogs instance.
72
+
73
+
## Data Model
74
+
75
+
This section describes the structure of the data that is transferred to the vlogs server.
76
+
77
+
### LogRecord fields
30
78
31
79
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):
32
80
@@ -44,7 +92,7 @@ Name | Description | Example | Optional
44
92
45
93
In addition any custom `extras' fields will be added as they are encountered.
46
94
47
-
## VictoriaLogs special fields
95
+
###VictoriaLogs special fields
48
96
49
97
VictoriaLogs handles three fields in a special way:
0 commit comments