loggy Build Status codecov Api Docs

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

This is inspired by simple-logging implementation, with additional features meant to support development of applications (as opposed to libraries).

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 extern crate loggy;

loggy::init(Loggy { prefix: "...", // Typically, the name of the program. showtime: true, // Or false. loglevel: LogLevel::Warn, // Or Info, or Error. }); ```

To provide user control over handling issues:

```rust

[macro_use]

extern crate loggy;

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

To deal with errors in processing stages:

```rust extern crate loggy;

{ let scope = loggy::ErrorsScope::new(); runprocessingstagewithpotentialerrors(); if scope.haderrors() { return; } } continuetonextprocessingstage(); ```

To test code that emits log messages;

```rust

[macro_use]

extern crate loggy;

testloggy!(testname, { runsomecode(); assert_log("\ 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>: <message>, where the 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.