Struct loggerv::Logger [] [src]

pub struct Logger { /* fields omitted */ }

Methods

impl Logger
[src]

[src]

Creates a new instance of the verbosity-based logger.

The default level is WARN. Color is enabled if the parent application or library is running from a terminal, i.e. running a tty. The default separator is the ": " string. The default output format is module path: message. The following default colors are used:

Level Color
Error Bright Red
Warn Bright Yellow
Info Bright Green
Debug Light Grey
Trace Grey

[src]

Sets the color for a level.

Example

#[macro_use] extern crate log;
extern crate loggerv;
extern crate ansi_term;

use log::Level;
use ansi_term::Colour;

fn main() {
    loggerv::Logger::new()
        .color(&Level::Error, Colour::Fixed(7))
        .init()
        .unwrap();

    error!("This is printed in light grey instead of bright red");
}

[src]

Sets the separator string.

The separator is the string between the "tag" and the message that make up a log statement. The tag will be colorized if enabled, while the message will not. The default is :.

If the level, line numbers, and module path are all not included in the log statement, then the separator is changed to the empty string to avoid printing a lone string or character before each message portion of the log statement.

Example

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

fn main() {
    loggerv::Logger::new()
        .separator(" = ")
        .init()
        .unwrap();

    error!("This is printed with an equal sign between the module path and this message");
}

[src]

Enables or disables colorizing the output.

If the logger is not used in a terminal, then the output is not colorized regardless of this value.

Example

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

fn main() {
    loggerv::Logger::new()
        .colors(false)
        .init()
        .unwrap();

    error!("This is printed without any colorization");
}

[src]

Disables colorizing the output.

The default is to colorize the output unless stdout and stderr are redirected or piped, i.e. not a tty.

Example

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

fn main() {
    loggerv::Logger::new()
        .no_colors()
        .init()
        .unwrap();

    error!("This is printed without any colorization");
}

[src]

Enables or disables including line numbers in the "tag" portion of the log statement.

The tag is the text to the left of the separator.

Example

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

fn main() {
    loggerv::Logger::new()
        .line_numbers(true)
        .init()
        .unwrap();

    error!("This is printed with the module path and the line number surrounded by
    parentheses");
}

[src]

Enables or disables including the level in the log statement's tag portion. The tag of the log statement is the text to the left of the separator.

If the level and the module path are both inculded, then the module path is surrounded by square brackets.

Example

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

fn main() {
    loggerv::Logger::new()
        .level(true)
        .init()
        .unwrap();

    error!("This is printed with the 'ERROR' and the module path is surrounded in square
    brackets");
}

[src]

Explicitly sets the log level instead of through a verbosity.

Example

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

fn main() {
    loggerv::Logger::new()
        .max_level(log::Level::Info)
        .init()
        .unwrap();

    error!("This is printed to stderr");
    warn!("This is printed to stderr");
    info!("This is printed to stdout");
    debug!("This is not printed to stdout");
    trace!("This is not printed to stdout");
}

[src]

Enables or disables including the module path in the "tag" portion of the log statement.

The tag is the text to the left of the separator. The default is to include the module path. Ifthe level is also included, the module path is surrounded by square brackets.

Example

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

fn main() {
    loggerv::Logger::new()
        .module_path(false)
        .init()
        .unwrap();

    error!("This is printed without leading module path and separator");
}

[src]

Disables the module path in the "tag" portion of the log statement.

The tag is the text to the left of the separator. The default is to include the module path.

Example

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

fn main() {
    loggerv::Logger::new()
        .no_module_path()
        .init()
        .unwrap();

    error!("This is printed without leading module path and separator");
}

[src]

Sets the base level.

The base level is the level used with zero (0) verbosity. The default is WARN. So, ERROR and WARN statements will be written and INFO statements will be written with a verbosity of 1 or greater. If the base level was changed to ERROR, then only ERROR statements will be written and WARN statements will be written with a verbosity of 1 or greater. Use this adjust the correlation of verbosity, i.e. number of -v occurrences, to level.

Example

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

fn main() {
    loggerv::Logger::new()
        .base_level(log::Level::Error)
        .verbosity(0)
        .init()
        .unwrap();

    error!("This is printed");
    warn!("This is not printed");
    info!("This is not printed");
}

Example

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

fn main() {
    loggerv::Logger::new()
        .base_level(log::Level::Info)
        .verbosity(0)
        .init()
        .unwrap();

    error!("This is printed");
    warn!("This is also printed");
    info!("This is now printed, too");
}

[src]

Sets the output for a level.

The output is either stderr or stdout. The default is for ERROR and WARN to be written to stderr and INFO, DEBUG, and TRACE to stdout.

Example

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

use log::Level;
use loggerv::Output;

fn main() {
    loggerv::Logger::new()
        .output(&Level::Error, Output::Stdout)
        .output(&Level::Warn, Output::Stdout)
        .output(&Level::Info, Output::Stderr)
        .output(&Level::Debug, Output::Stderr)
        .output(&Level::Trace, Output::Stderr)
        .verbosity(0)
        .init()
        .unwrap();

    error!("This is printed on stdout instead of stderr");
    warn!("This is printed on stdout instead of stderr");
    info!("This is printed on stderr instead of stdout");
    debug!("This is printed on stderr instead of stdout");
    trace!("This is printed on stderr instead of stdout");
}

[src]

Sets the level based on verbosity and the offset.

A verbosity of zero (0) is the default, which means ERROR and WARN log statements are printed to stderr. No other log statements are printed on any of the standard streams (stdout or stderr). As the verbosity is increased, the log level is increased and more log statements will be printed to stdout.

Example

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

fn main() {
    loggerv::Logger::new()
        .verbosity(1)
        .init()
        .unwrap();

    error!("This is printed to stderr");
    warn!("This is printed to stderr");
    info!("This is printed to stdout");
    debug!("This is not printed to stdout");
    trace!("This is not printed to stdout");
}

[src]

Initializes the logger.

This also consumes the logger. It cannot be further modified after initialization.

Example

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

fn main() {
    loggerv::Logger::new()
        .init()
        .unwrap();

    error!("This is printed to stderr");
    warn!("This is printed to stderr");
    info!("This is not printed to stdout");
    debug!("This is not printed to stdout");
    trace!("This is not printed to stdout");
}

Example

If the tag will be empty because the level, line numbers, and module path were all disabled, then the separator is changed to the empty string to avoid writing a long character in front of each message for each log statement.

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

fn main() {
    loggerv::Logger::new()
        .module_path(false)
        .level(false)
        .line_numbers(false)
        .init()
        .unwrap();

    error!("This is printed to stderr without the separator");
    warn!("This is printed to stderr without the separator");
    info!("This is not printed to stdout");
    debug!("This is not printed to stdout");
    trace!("This is not printed to stdout");
}

Trait Implementations

impl Debug for Logger
[src]

[src]

Formats the value using the given formatter.

impl Clone for Logger
[src]

[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more

impl PartialEq for Logger
[src]

[src]

This method tests for self and other values to be equal, and is used by ==. Read more

[src]

This method tests for !=.

impl Log for Logger
[src]

[src]

Determines if a log message with the specified metadata would be logged. Read more

[src]

Logs the Record. Read more

[src]

Flushes any buffered records.

impl Default for Logger
[src]

[src]

Returns the "default value" for a type. Read more