• Stars
    star
    415
  • Rank 104,007 (Top 3 %)
  • Language
    Rust
  • License
    Apache License 2.0
  • Created over 8 years ago
  • Updated 7 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Simple Logging Facility for Rust

simplelog Build Status Coverage Status Crates.io Crates.io

A simple and easy-to-use logging facility for Rust's log crate

simplelog does not aim to provide a rich set of features, nor to provide the best logging solution. It aims to be a maintainable, easy to integrate facility for small to medium sized projects, that find env_logger to be somewhat lacking in features. In those cases simplelog should provide an easy alternative.

Concept

simplelog provides a series of logging facilities, that can be easily combined.

  • SimpleLogger (very basic logger that logs to stderr/out, should never fail)
  • TermLogger (advanced terminal logger, that splits to stderr/out and has color support) (can be excluded on unsupported platforms)
  • WriteLogger (logs to a given struct implementing Write. e.g. a file)
  • CombinedLogger (can be used to form combinations of the above loggers)

Usage

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

use simplelog::*;

use std::fs::File;

fn main() {
    CombinedLogger::init(
        vec![
            TermLogger::new(LevelFilter::Warn, Config::default(), TerminalMode::Mixed, ColorChoice::Auto),
            WriteLogger::new(LevelFilter::Info, Config::default(), File::create("my_rust_binary.log").unwrap()),
        ]
    ).unwrap();

    error!("Bright red error");
    info!("This only appears in the log file");
    debug!("This level is currently not enabled for any logger");
}

Results in

$ cargo run --example usage
   Compiling simplelog v0.12.0 (file:///home/drakulix/Projects/simplelog)
     Running `target/debug/examples/usage`
[ERROR] Bright red error

and my_rust_binary.log

11:13:03 [ERROR] usage: Bright red error
11:13:03 [INFO] usage: This only appears in the log file

Getting Started

Just add

[dependencies]
simplelog = "^0.12.0"

to your Cargo.toml

ANSI color and style support

This crate can internally depend on a paris crate to provide support for ANSI color and styles. To use this feature you need to set a paris feature, like this:

[dependencies]
simplelog = { version = "^0.11.0", features = ["paris"] }

in your Cargo.toml

After this you can use e.g. the following call:

info!("I can write <b>bold</b> text or use tags to <red>color it</>");

This will automatically generates terminal control sequences for desired styles.

More formatting info: paris crate documentation

Documentation

Contributing

If you wish to contribute your own logger to simplelog or advance/extend existing loggers, feel free to create a pull request. Just don't blindly assume, that your logger will be accepted. The rational about this library is, that it is simple to use. This mostly comes down to a small and easy API, but also includes things like the amount of added dependencies. If you feel unsure about your plans, feel free to create an issue to talk about your ideas.

Happy Coding!

More Repositories

1

fireplace

Modular wayland window manager written in rust
Rust
602
star
2

sway-gnome

Opinionated Sway Configuration using GNOME session services, for GNOME >= 3.34
Makefile
136
star
3

googlehome

Google Home Integration for Home-Assistant
Python
29
star
4

wlc.rs

Safe Rust Cloudef/wlc bindings (Wayland Compositor C Library)
Rust
27
star
5

ScrollsModLoader

A Mod Loader Framework for the game "Scrolls" by Mojang
C#
15
star
6

shipwreck

Configurable Docker socket proxy
Rust
7
star
7

nvscreencopy

A userspace utility to mirror outputs on wayland to nvidia gpus
Rust
7
star
8

sunrise

Some hacks and failed experiments surrounding nvidia's gamestream protocol and sunshine/moonlight implementations
Rust
7
star
9

zwreec

Twee to Z-Code Compiler in Rust
Rust
7
star
10

37c3-container-workshop

A project for learning about containers during 37c3
TypeScript
5
star
11

infinity

A Silverblue based OSTree Image with the COSMIC desktop environment
Dockerfile
5
star
12

plugin.program.steam.streaming

Kodi Addon to start Steam In-Home Streaming directly
Python
5
star
13

knex

KNowledge EXchange platform
JavaScript
4
star
14

VK_hdr_layer

Hacks. Don't use.
C++
4
star
15

taskqueue

TaskQueue is a libdispatch inspired threading library for Rust
Rust
3
star
16

opengles_graphics

An OpenGL ES 2D back-end for the Piston game engine
Rust
3
star
17

objectCraft

An Objective-C cross-platform Minecraft PC and Pocket Edition dedicated Server
Objective-C
3
star
18

ghlapi_proxy

Google Home Local API Proxy
Rust
2
star
19

spotify-sensor

Custom Spotify sensor integration for Home-Assistant
Python
1
star
20

unifi-dns-gen

A hosts-file generator by aliases made in a UniFi controller to be run on a UDM
Python
1
star
21

libdisplay-info-rs

Rust
1
star
22

prog-lang-speed-dating

Slides and resources from Programmming Language πŸ’» Speed Dating πŸ’˜
1
star