3 unstable releases
new 0.2.1 | Nov 20, 2024 |
---|---|
0.2.0 | Nov 2, 2024 |
0.1.0 | Jan 18, 2024 |
#348 in Encoding
1,511 downloads per month
Used in 3 crates
(via picodata-plugin)
57KB
1K
SLoC
Tarolog
Library for flexible configuration of tarantool logs. Allows you to set your own log format or choose from builtin formats. Supports "data injectors" for enrichment log records with any data (e.g. instance-id or request-id). All formats are applying to tarantool internal logs as well.
Builtin formats
- JsonRaw - json logs. This format is as close as possible to an original tarantool 'json' format.
- Json - json logs, use
serde
library for a log record generation. - Plain - plain text. This format is as close as possible to an original tarantool 'plain' format.
Also, you can implement your own format.
Benchmark
generate file size (lines per sec) bigger is better |
generated stdout output (mb per sec) bigger is better |
|
---|---|---|
tarantool-json | 144135 | 49,675 |
tarolog-json | 203785 | 82 |
tarolog-json-serde | 188217 | 70,25 |
tarantool-plain | 210876 | 29,475 |
tarolog-plain | 231691 | 29,95 |
See a "bench" package for familiarize with benchmark process.
Example
In this example we use json format with injectors that propagate two fields:
- key: "additional data", value: true
- key: "request_id", value: {request id extracted from fiber local storage}
use tarolog;
use tarolog::Format;
use tarantool;
use tarantool::ffi;
use std::collections::HashMap;
use log::info;
fn main() {
tarolog::set_default_logger_format(Format::Json(Some(|| {
let mut additional_info =
HashMap::from([("additional data".to_string(), serde_json::Value::Bool(true))]);
// lua available only in tx thread, check it
let cord_is_main = unsafe { ffi::tarantool::cord_is_main() };
if cord_is_main {
let lua = tarantool::lua_state();
if let Ok(Some(rid)) = lua.eval("return require('fiber').self().storage['rid']") {
additional_info.insert("request_id".to_string(), serde_json::Value::String(rid));
}
}
additional_info
})));
info!("now new format is installed");
}
Tests
tarantool-test is required.
Run unit tests
cargo test
Run integration tests
cargo build; tarantool-test -p ./target/debug/libtests.so -- -i tests/test_init.lua
All tests
make test
Dependencies
~11MB
~218K SLoC