All Projects → elichai → Log Derive

elichai / Log Derive

Licence: other
A procedural macro for auto logging output of functions

Programming Languages

rust
11053 projects
metaprogramming
66 projects

Labels

Projects that are alternatives of or similar to Log Derive

Json Logging Python
Python logging library to emit JSON log that can be easily indexed and searchable by logging infrastructure such as ELK, EFK, AWS Cloudwatch, GCP Stackdriver
Stars: ✭ 143 (-13.33%)
Mutual labels:  logging
Dotnetcore
.NET 5 Nuget Packages.
Stars: ✭ 146 (-11.52%)
Mutual labels:  logging
Investigator
Interactive and asynchronous logging tool for Node.js. An easier way to log & debug complex requests directly from the command line (experimental).
Stars: ✭ 155 (-6.06%)
Mutual labels:  logging
Co
Art of C++. Flag, logging, unit-test, json, go-style coroutine and more.
Stars: ✭ 2,264 (+1272.12%)
Mutual labels:  logging
Apollo Link Logger
A logger for Apollo Link that resembles redux-logger
Stars: ✭ 148 (-10.3%)
Mutual labels:  logging
Volkszaehler.org
Open Source Smart Meter with focus on privacy - you remain the master of your data.
Stars: ✭ 150 (-9.09%)
Mutual labels:  logging
Wonolog
Monolog-based logging package for WordPress.
Stars: ✭ 142 (-13.94%)
Mutual labels:  logging
Dategrep
print lines matching a time range
Stars: ✭ 159 (-3.64%)
Mutual labels:  logging
Dagger
Dagger 是一个基于 Loki 的日志查询和管理系统,它是由达闼科技( CloudMinds )云团队的`大禹基础设施平台`派生出来的一个项目。Dagger 运行在 Loki 前端,具备日志查询、搜索,保存和下载等特性,适用于云原生场景下的容器日志管理场景。
Stars: ✭ 149 (-9.7%)
Mutual labels:  logging
Timber Ruby
🌲 Great Ruby logging made easy.
Stars: ✭ 154 (-6.67%)
Mutual labels:  logging
Spdlog
Fast C++ logging library.
Stars: ✭ 13,355 (+7993.94%)
Mutual labels:  logging
Filebeat Kubernetes
Filebeat container, alternative to fluentd used to ship kubernetes cluster and pod logs
Stars: ✭ 147 (-10.91%)
Mutual labels:  logging
Clog
Package clog is a channel-based logging package for Go
Stars: ✭ 151 (-8.48%)
Mutual labels:  logging
Zf log
Core logging library for C/ObjC/C++
Stars: ✭ 145 (-12.12%)
Mutual labels:  logging
Wormholy
iOS network debugging, like a wizard 🧙‍♂️
Stars: ✭ 2,010 (+1118.18%)
Mutual labels:  logging
Array Redactor
A PHP package to redact array values by their keys.
Stars: ✭ 144 (-12.73%)
Mutual labels:  logging
Dotzu
📱👀 In-App iOS Debugging Tool With Enhanced Logging, Networking Info, Crash reporting And More.
Stars: ✭ 1,802 (+992.12%)
Mutual labels:  logging
React Native Network Logger
An HTTP network request monitor for React Native with in-app interface for iOS and Android with no native code
Stars: ✭ 161 (-2.42%)
Mutual labels:  logging
Java Markdown Generator
Java library to generate markdown
Stars: ✭ 159 (-3.64%)
Mutual labels:  logging
Logsuck
Easy log aggregation, indexing and searching
Stars: ✭ 154 (-6.67%)
Mutual labels:  logging

log-derive

Build Status Latest version Documentation License dependency status

A Rust macro to part of the log facade that auto generates loggings for functions output.

Usage

Add this to your Cargo.toml:

[dependencies]
log-derive = "0.3"
log = "0.4"

and for Rust Edition 2015 add this to your crate root:

#[macro_use]
extern crate log_derive;
extern crate log;

In Rust Edition 2018 you can simply do:

use log_derive::logfn;

After that all you need is to add the according macro above a function that,
either returns an output or receive an input that implements the Debug trait.

Examples

 #[logfn(Err = "Error", fmt = "Failed Sending Packet: {:?}")]
 fn send_hi(addr: SocketAddr) -> Result<(), io::Error> {
     let mut stream = TcpStream::connect(addr)?;
     stream.write(b"Hi!")?;
     Ok( () )
 }

#[logfn(Trace)]
#[logfn_inputs(Info)]
fn test_log(a: u8) -> String {
  (a*2).to_string()
}

#[logfn(Trace, fmt = "testing the num: {:?}")]
fn test_log(a: u8) -> String {
  (a*2).to_string()
}

Output

The output of the fibonacci example:

17:15:24 [TRACE] (1) fibonacci: [examples/fibonacci.rs:16] fibonacci(n: 5)
17:15:24 [TRACE] (1) fibonacci: [examples/fibonacci.rs:16] fibonacci(n: 4)
17:15:24 [TRACE] (1) fibonacci: [examples/fibonacci.rs:16] fibonacci(n: 3)
17:15:24 [TRACE] (1) fibonacci: [examples/fibonacci.rs:16] fibonacci(n: 2)
17:15:24 [TRACE] (1) fibonacci: [examples/fibonacci.rs:16] fibonacci(n: 1)
17:15:24 [ INFO] fibonacci() -> 1
17:15:24 [TRACE] (1) fibonacci: [examples/fibonacci.rs:16] fibonacci(n: 0)
17:15:24 [ INFO] fibonacci() -> 1
17:15:24 [ INFO] fibonacci() -> 2
17:15:24 [TRACE] (1) fibonacci: [examples/fibonacci.rs:16] fibonacci(n: 1)
17:15:24 [ INFO] fibonacci() -> 1
17:15:24 [ INFO] fibonacci() -> 3
17:15:24 [TRACE] (1) fibonacci: [examples/fibonacci.rs:16] fibonacci(n: 2)
17:15:24 [TRACE] (1) fibonacci: [examples/fibonacci.rs:16] fibonacci(n: 1)
17:15:24 [ INFO] fibonacci() -> 1
17:15:24 [TRACE] (1) fibonacci: [examples/fibonacci.rs:16] fibonacci(n: 0)
17:15:24 [ INFO] fibonacci() -> 1
17:15:24 [ INFO] fibonacci() -> 2
17:15:24 [ INFO] fibonacci() -> 5
17:15:24 [TRACE] (1) fibonacci: [examples/fibonacci.rs:16] fibonacci(n: 3)
17:15:24 [TRACE] (1) fibonacci: [examples/fibonacci.rs:16] fibonacci(n: 2)
17:15:24 [TRACE] (1) fibonacci: [examples/fibonacci.rs:16] fibonacci(n: 1)
17:15:24 [ INFO] fibonacci() -> 1
17:15:24 [TRACE] (1) fibonacci: [examples/fibonacci.rs:16] fibonacci(n: 0)
17:15:24 [ INFO] fibonacci() -> 1
17:15:24 [ INFO] fibonacci() -> 2
17:15:24 [TRACE] (1) fibonacci: [examples/fibonacci.rs:16] fibonacci(n: 1)
17:15:24 [ INFO] fibonacci() -> 1
17:15:24 [ INFO] fibonacci() -> 3
17:15:24 [ INFO] fibonacci() -> 8

If you expand the output of the #[logfn] macro the resulting code will look something like this:

fn fibonacci(n: u32) -> u32 {
    let result = (move || match n {
        0 => 1,
        1 => 1,
        _ => fibonacci(n - 1) + fibonacci(n - 2),
    })();
    log::log!(log::Level::Info, "fibonacci() -> {}", result);
    result
}

If the function returns a Result it will match through it to split between the Ok LogLevel and the Err LogLevel

The expansion of the #[logfn_inputs] macro will look something like this:

fn fibonacci(n: u32) -> u32 {
    log::log!(log::Level::Info, "fibonacci(n: {:?})", n);
    match n {
        0 => 1,
        1 => 1,
        _ => fibonacci(n - 1) + fibonacci(n - 2),
    }
}

Of course the log! macro will be expanded too and it will be a bit more messy.

Note

The log_ts feature will fail your compilation in a no-std enviroment. it can only be used where std is available. (as it uses std::time::Instant)

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].