A loki logger for the log facade

Related tags

Logging loki-logger
Overview

Loki Logger

Build Status Crates.io Crates.io Documentation

A loki logger for the log facade.

Examples

extern crate log;
extern crate loki_logger;
use log::LevelFilter;

#[tokio::main]
async fn main() {
    loki_logger::init(
        "http://loki:3100/loki/api/v1/push",
        log::LevelFilter::Info,
    ).unwrap();

    log::info!("Logged into Loki !");
}
extern crate log;
extern crate loki_logger;
use std::iter::FromIterator;
use std::collections::HashMap;
use log::LevelFilter;

#[tokio::main]
async fn main() {
    let initial_labels = HashMap::from_iter([
        ("application".to_string(), "loki_logger".to_string()),
        ("environment".to_string(), "development".to_string()),
    ]);

    loki_logger::init_with_labels(
        "http://loki:3100/loki/api/v1/push",
        log::LevelFilter::Info,
        initial_labels,
    ).unwrap();

    log::info!("Logged into Loki !");
}

Use with extra labels

Starting from 0.4.7, the log crate started introducing the new key/value system for structured logging.

This crate makes heavy use of such system as to create and send custom loki labels.

If you want to use this system, you have to use the git version of the log crate and enable the kv_unstable feature:

[dependencies.log]
# It is recommended that you pin this version to a specific commit to avoid issues.
git = "https://github.com/rust-lang/log.git"
features = ["kv_unstable"]

This feature will allow you to use the log facade as such:

extern crate log;
extern crate loki_logger;
use std::iter::FromIterator;
use std::collections::HashMap;
use log::LevelFilter;

#[tokio::main]
async fn main() {
    let initial_labels = HashMap::from_iter([
        ("application".to_string(), "loki_logger".to_string()),
        ("environment".to_string(), "development".to_string()),
    ]);

    loki_logger::init_with_labels(
        "http://loki:3100/loki/api/v1/push",
        log::LevelFilter::Info,
        initial_labels,
    ).unwrap();

    // Due to stabilization issue, this is still unstable,
    // the log macros needs to have at least one formatting parameter for this to work.
    log::info!(foo = "bar"; "Logged into Loki !{}", "");
}
You might also like...
rt-history: An RT-safe history log with error checking

rt-history: An RT-safe history log with error checking This is a bounded wait-free thread synchronization primitive which allows you to record the tim

Log for concurrent workloads, with support for atomic batches and in-order recovery

sharded-log A batch-oriented multi-threaded sharded log for workloads that occasionally flush logs into some other system. All batches have a 32-bit C

A cool log library built using rust-lang

RustLog A cool log library built using rust-lang Installation: Cargo.toml rustlog = { git = "https://github.com/krishpranav/rustlog" } log = "0.4.17"

godot-logger is an easy-to-use logger for godot-rust projects.

godot-logger is an easy-to-use logger for godot-rust projects. It prints logs to Godot's output console and supports module-specific log levels.

Easy c̵̰͠r̵̛̠ö̴̪s̶̩̒s̵̭̀-t̶̲͝h̶̯̚r̵̺͐e̷̖̽ḁ̴̍d̶̖̔ ȓ̵͙ė̶͎ḟ̴͙e̸̖͛r̶̖͗ë̶̱́ṉ̵̒ĉ̷̥e̷͚̍ s̷̹͌h̷̲̉a̵̭͋r̷̫̊ḭ̵̊n̷̬͂g̵̦̃ f̶̻̊ơ̵̜ṟ̸̈́ R̵̞̋ù̵̺s̷̖̅ţ̸͗!̸̼͋

Rust S̵̓i̸̓n̵̉ I̴n̴f̶e̸r̵n̷a̴l mutability! Howdy, friendly Rust developer! Ever had a value get m̵̯̅ð̶͊v̴̮̾ê̴̼͘d away right under your nose just when

Loki, God of Mischief

Loki Loki is an experimental programming language that I am building both to learn more about compilers and test ideas about language design. Compiler

Async filesystem facade for Rust!

floppy-disk floppy disk is a WIP, async-only filesystem facade for Rust. What? Have you ever worked with std::fs? tokio::fs? Then you've probably real

Log agent to replay time-stamped log stream

replayman Log agent to replay time-stamped log stream. Getting started Installation cargo install replayman Prepare for your data TSV with a header li

A pretty, easy-to-use logger for Rust.
A pretty, easy-to-use logger for Rust.

pretty-env-logger A simple logger built on top of env_logger. It is configured via an environment variable and writes to standard error with nice colo

A Rust logger with various features.

Moe Logger (>ω<) Another logger based on pretty-env-logger and env_logger. Allow writing log to file with features like formatting, file rotation. Usa

HTTP request logger

nosy - HTTP request logger How hard can it be to build your own HTTP request logger in Rust? Well, not that easy if you've never written a webapp in R

A standalone, `#![no_std]`-friendly `Logger` crate.

A standalone, #![no_std]-friendly Logger crate. Based on the design of the logger built into the bootloader crate and meant to be used in OS kernels.

Another Key Logger Yet. Rust.

Another Key Logger Yet. Rust. For my very first experience of working with Rust, I decided to manage the keyboard, this time by logging and writing th

A pretty, sensible logger for Rust - ideal for running examples and tests on a crate of choice
A pretty, sensible logger for Rust - ideal for running examples and tests on a crate of choice

sensible-env-logger A pretty, sensible logger for Rust - ideal for running examples and tests on a crate of choice. This is a thin wrapper around pret

Rall is an incredibly simple and intuitive logger
Rall is an incredibly simple and intuitive logger

Really...? Another Logging Library? Yes! :P rall is an incredibly simple and intuitive logger, consider this crate a failure if you can't get setup wi

API and logger for GBFS endpoints, noticeably Velib' in Paris

GBFS Watcher A daemon which logs Velib' stations statuses and provides a REST endpoint to access data. Velib' API is built over GBFS v1, so this API c

🔥 📝  (fwdt)
🔥 📝 (fwdt) "few word do trick" is a cross platform manual fast logger

Few Word Do Trick (fwdt) Few Word Do Trick (fwdt) is a cross-platform general purpose fast logger for humans that supports incomplete csvs for a bette

A dead simple logger that works globally and across threads.

Woody A logger for Rust that's *actually* easy to use. Features Easy to use: Just import the macros and you're good to go. No need to configure anythi

⚙️ Pre-commit hook for downgrading Python logger syntax

printf-log-formatter Automatically convert f-strings and str.format() syntax to printf-style strings. In other words, this syntax logger.error(f"{1}")

Comments
  • Add async tests

    Add async tests

    Add two async tests. One of them (async_logging_from_sync_thread) causes an error with the message there is no reactor running, must be called from the context of a Tokio 1.x runtime. See issue #1 for more details.

    I put the tests into separate file in order to avoid initializing the logger twice in a single application.

    opened by dfaust 1
  • "no reactor running" error when log! is called from a sync thread

    Thanks for creating this crate. I was playing around with it when I got the error message there is no reactor running, must be called from the context of a Tokio 1.x runtime. I assume it happens because a dependency is spawning a thread and uses the log! macro from that thread.

    I created a test to confirm my suspicion and it fails with the same error message. I will create a MR for that in a moment.

    Would it be possible to send the logs to an async task first and send it to loki from there? It might make sense to do that anyway in order to implement a queue and send logs in batches.

    opened by dfaust 1
Owner
Thomas Nicollet
Student at EPITECH Lyon, France
Thomas Nicollet
A pretty, easy-to-use logger for Rust.

pretty-env-logger A simple logger built on top of env_logger. It is configured via an environment variable and writes to standard error with nice colo

Sean McArthur 390 Dec 29, 2022
A Rust logger with various features.

Moe Logger (>ω<) Another logger based on pretty-env-logger and env_logger. Allow writing log to file with features like formatting, file rotation. Usa

Rui Li 4 Sep 24, 2021
HTTP request logger

nosy - HTTP request logger How hard can it be to build your own HTTP request logger in Rust? Well, not that easy if you've never written a webapp in R

Manuel Hutter 1 Nov 26, 2021
A standalone, `#![no_std]`-friendly `Logger` crate.

A standalone, #![no_std]-friendly Logger crate. Based on the design of the logger built into the bootloader crate and meant to be used in OS kernels.

Kenny Strawn 1 Feb 6, 2022
Another Key Logger Yet. Rust.

Another Key Logger Yet. Rust. For my very first experience of working with Rust, I decided to manage the keyboard, this time by logging and writing th

(Not) Kearash 0 May 3, 2022
A pretty, sensible logger for Rust - ideal for running examples and tests on a crate of choice

sensible-env-logger A pretty, sensible logger for Rust - ideal for running examples and tests on a crate of choice. This is a thin wrapper around pret

Ritvik Nag 3 Aug 9, 2022
Rall is an incredibly simple and intuitive logger

Really...? Another Logging Library? Yes! :P rall is an incredibly simple and intuitive logger, consider this crate a failure if you can't get setup wi

Hamothy 4 Sep 5, 2022
A dead simple logger that works globally and across threads.

Woody A logger for Rust that's *actually* easy to use. Features Easy to use: Just import the macros and you're good to go. No need to configure anythi

Travis A. Wagner 11 Apr 13, 2023
A nginx log explorer

Rhit reads your nginx log files in their standard location(even gzipped), does some analysis and tells you about it in pretty tables in your console,

Canop 700 Dec 27, 2022
Compute and derive metrics by watching a log file

Export Prometheus metrics from your web server's access log Web servers only offer limited metrics. For example, nginx only offers stub_status unless

Remi Rampin 1 Nov 4, 2022