loggy Build Status codecov Api Docs

An opinionated library for developing and testing rust applications that use logging.

This was initially inspired by simple-logging implementation, with additional features focusing on development of applications (as opposed to libraries). Structured messages were influenced by slog, but allow for nested structures and provide only a single format targeting human readability.

Building and Testing

To build run either cargo build or cargo make build.

To test, run either RUST_TEST_THREADS=1 cargo test or cargo make test. Single thread testing is required due to the rust log facade mandating the use of a single global logger.

Examples

The main program will need to set up the logger:

rust log::set_logger(&Loggy { prefix: "...", // Typically, the name of the program. show_time: true, // Or false. show_thread: true, // Or false. }).unwrap(); log::set_max_level(log::LevelFilter::Info); // Or whatever level you want.

To override the default module name prefix and replace it with an arbitrary scope name:

```rust

[macro_use]

extern crate loggy;

loggy::innamedscope("scope name", || { /// Log messages generated here will be prefixed by the scope instead of the module name. ... }); ```

To provide user control over whether issues are errors or warnings:

```rust

[macro_use]

extern crate loggy;

let isissueanerror = decidebasedoncommandlinearguments(); if didissueoccur() { note!(isissueanerror, "issue occured"); provideworkaround(); } else { proceed_normally(); } ```

To count the number of errors raised by some code (normally error! causes a panic!):

```rust extern crate loggy;

let errorscount = loggy::counterrors(|| { /// Errors logged here will be counted. }); ```

To test code that emits log messages;

```rust

[macro_use]

extern crate loggy;

testloggy!(testname, { runsomecode(); assert_log(r###" test: [] : ... "###); });

```

Motivation

This library was written to support the development of a non-trivial Rust application that uses logging. The functionality provided here was factored out, both to keep it isolated from the application itself, and in the hope it might prove useful to others.

Technically, this library is an implementation for the Rust log facade, with a few additional features thrown in. The implementation and features were designed to support a specific development workflow.

Features

As an implementation of the log facade, this library is pretty basic and standard. Messages are emitted to the standard error stream. The message format is <prefix>[<thread>]: <time> [<level]>] <module/scope>: <message>, where the thread and time may be omitted.

Additional features reflect the library's opinionated nature:

Logging Features

Development Features

Testing Features

License

loggy is licensed under the MIT License.