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
This package provides a Python log handler for Victoria Logs. The log handler is designed to work with Python's default logging module and will send all log events to a configured Victoria Logs server for log ingestion.
15
+
**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 and zero friction.
16
16
17
17
## Key Features
18
18
19
-
- Asynchronous design: Log events are queued and then processed in a separate thread so that the performance impact on the main program remains minimal.
20
-
- Request batching: Log events are processed without delay. Multiple log events will be sent in a single request as batch to minimize the number of requests to the VictoriaLogs server.
21
-
- Supports extras: Extra fields are supported. This includes non-standard types like sets and datetime objects. Fields that can not be serialized to JSON (e.g. functions) will be converted into their string representation
22
-
- Supports dict config: The handler supports dict configuration, e.g. for a Django server
19
+
-**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
+
-**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
+
23
+
-**Rich Exception Handling**: Automatically captures and flattens stack traces. Log messages include both the exception name and the full traceback as searchable fields.
24
+
25
+
-**Smart Serialization**: Supports extra fields out of the box. It intelligently handles non-standard types like set and datetime. Any non-serializable objects (such as functions or custom classes) are gracefully converted to their string representation.
26
+
27
+
-**Standard Configuration Support**: Fully compatible with `logging.config.dictConfig`, making it easy to drop into frameworks like Django, Flask, or FastAPI.
28
+
29
+
## Technical details
30
+
31
+
This section documents technical details of the solution.
32
+
33
+
### LogRecord fields
34
+
35
+
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):
36
+
37
+
Name | Description | Example | Optional
38
+
-- | -- | -- | --
39
+
`exception_name` | Name of the exception | `ZeroDivisionError` | yes
40
+
`exception` | Full traceback of the exception | `Traceback ...` | yes
41
+
`function` | Name of the function that emitted the log event | `my_function` | no
42
+
`level` | Name of the level of the emitted log event | `INFO` | no
43
+
`line_number` | Line number where the log event was emitted | `89` | no
44
+
`logger` | Name of the related Python logger | `my_package.my_module` | no
45
+
`message` | The logged message | 'This is a log entry' | no
46
+
`stream` | Name of the top-level Python package that emitted the log the event. | `my_package` | no
47
+
`timestamp` | Timestamp of the log event, represented as fractional UNIX epoch | `1775081468.4308655` | no
48
+
49
+
In addition any custom `extras' fields will be added as they are encountered.
50
+
51
+
### VictoriaLogs special fields
52
+
53
+
VictoriaLogs handles three fields in a special:
54
+
55
+
-`_msg`: The logged message. This is a mandatory field and is mapped to `message`.
56
+
-`_time`: The timestamp of the log event. This field and is mapped to `timestamp`.
57
+
-`_stream`: The source of a log event, which is used to group and filter logs. This field is mapped to `stream`.
58
+
59
+
For more information please also see [VictoriaLogs Data model](https://docs.victoriametrics.com/victorialogs/keyconcepts/#data-model).
0 commit comments