[][src]Crate poly_logger


This crate provides several useful log interface implementations.

GenLogger is a generic logger which allows custom message and time formats for a logger. The target for the log messages can by anything implementing Write + Sync + Send + 'static, such as std::fs::File std::io::Stderr or std::io::Stdout

StdoutLogger, StderrLogger, and FileLogger are wrappers for GenLogger which each implement output to their respective sink types.

PolyLogger is a container for other loggers. For example, you may want to log certain messages to STDERR in one format, and others to go to a File in a different format. You simply create a FileLogger, a StderrLogger, and then add both to a new PolyLogger.

In each logger class, you call init() to assign the class instance to be the Log implementor for your application.

The examples directory provides use cases for each of the classes.


The author is new to Rust and this is an early release of this crate. This crate will evolve as my familiarity with the language grows, and as I start using this crate in my own projects. I will however not break the current API without a major revision number change.

Future Work

  • Reduce the use of unwrap() and do some proper error handling/propagation
  • Modify PolyLogger to use producer/consumer queue to minimize the cost of logging in the main application thread
  • Possibly add producer/consumer queue to GenLogger
  • Add unit tests
  • Add options to FileLogger to create an auto-naming and/or auto-incrementing file naming convention. E.g. Perhaps set the filename to be "log.{yyyymmdd}.{hhmmss}". I.e. Add the same flexibility we have for the log messages to the log file name itself.
  • Look into replacement for strfmt for message formatting. Perhaps include some statically defined canned options or wait for a more efficient implementation when the rust language allows it.



Implements a GenLogger that outputs to File


Implements a generic logger for use with different types of writers


Implements a super-logger that can redirect to other loggers


Implements a GenLogger that outputs to Stderr


Implements a GenLogger that outputs to Stdout