1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
       html_favicon_url = "http://www.rust-lang.org/favicon.ico",
       html_root_url = "http://doc.rust-lang.org/")]
#![warn(missing_docs)]

//! A logger that can write the log to standard error or to a fresh file in a configurable folder
//! and allows custom logline formats.
//! It had started as an extended copy of [env_logger](http://rust-lang.github.io/log/env_logger/).
//!
//! # Usage
//!
//! This crate is on [crates.io](https://crates.io/crates/flexi_logger) and
//! can be used by adding `flexi_logger` to the dependencies in your
//! project's `Cargo.toml`.
//!
//! ```toml
//! [dependencies]
//! flexi_logger = "^0.5.1"
//! log = "*"
//! ```
//!
//! and this to your crate root:
//!
//! ```text
//! extern crate flexi_logger;
//! #[macro_use]
//! extern crate log;
//! ```
//!
//! The latter is needed because flexi_logger plugs into the standard Rust logging facade given by the
//! [log crate](http://rust-lang.github.io/log/log/),
//! and you use the ```log``` macros to write log lines from your code.
//!
//! Early in the start-up of your program, call something like
//!
//! ```text
//!    flexi_logger::LogOptions::new()
//!        .log_to_file(true)
//!        // ... your configuration options go here ...
//!        .init(Some("info".to_string()))
//!        .unwrap_or_else(|e| panic!("Logger initialization failed with {}", e));
//! ```
//!
//! The configuration options allow e.g. to
//!
//! *  decide whether you want to write your logs to stderr (like with env_logger), or to a file,
//! *  configure the folder in which the log files are created,
//! *  specify the line format for the log lines
//!
//! See [LogOptions](struct.LogOptions.html) for a full description of all configuration options.

extern crate chrono;
extern crate glob;
extern crate log;
extern crate regex;

macro_rules! print_err {
    ($($arg:tt)*) => (
        {
            use std::io::prelude::*;
            if let Err(e) = write!(&mut ::std::io::stderr(), "{}\n", format_args!($($arg)*)) {
                panic!("Failed to write to stderr.\
                    \nOriginal error output: {}\
                    \nSecondary error writing to stderr: {}", format!($($arg)*), e);
            }
        }
    )
}


mod flexi_error;
mod flexi_logger;
mod flexi_writer;
mod formats;
mod log_options;

pub use log::{LogLevel, LogLevelFilter, LogRecord};
pub use formats::*;
pub use log_options::LogOptions;
pub use flexi_error::FlexiLoggerError;


pub use log_options::LogConfig;
pub use flexi_logger::FlexiLogger;
pub use flexi_logger::init;