[][src]Crate micrologger

A Tiny Structured Logging Utility

This is a lightweight logging utility that does little more than structure messages consistently and print them to standard out.

This logging facility is a simple object that should be passed around to anything that needs to do logging. I recommend making it a part of your application context so that it is simply passed along with the rest of your application information. Begin by instantiating the object:

let logger = micrologger::Logger::new(micrologger::json_stdout, "a-host", "an-app")

This API is fairly low-level and works best if clients wrap helper functions to build the log entries around the basic logging function.

fn log_app_start(logger: micrologger::Logger) {
    logger.log("app-start", HashMap::new());

fn log_method_start(logger: micrologger::Logger, method_name: str) {
    let mut msg = Hashmap::new();
    msg.insert("method-name", method_name);
    logger.log("method-start", msg);



This defines the structured of an entry on disk. You will never create one of these directly, however you can always deserialize one from a line in the log file:


The logger class



This allows the definition of a custom format closure. The trait provides both immutable and mutable logging methods for different scenarios. For instance, Iron middleware does not allow mutability in the handlers, and so a logging middleware must be immutable. This effectively means that for Iron, logging can only go to stdout.



Standard formatter which converts entry into a JSON object and prints it to standard out.