tarolog

Crates.iotarolog
lib.rstarolog
version0.2.1
sourcesrc
created_at2024-01-18 10:45:31.581419
updated_at2024-11-20 14:38:29.843157
descriptionLibrary for flexible configuration of tarantool logs
homepage
repositoryhttps://git.picodata.io/picodata/picodata/tarolog
max_upload_size
id1104075
size56,284
(picodata-account)

documentation

README

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
Commit count: 0

cargo fmt