pub trait LogFormatter: Send + Sync + 'static {
    type Output: Display + Send + Sync + 'static;

    // Required method
    fn format(&self, conn: &Conn, color: bool) -> Self::Output;
}
Expand description

The interface to format a &[Conn] as a Display-able output

In general, the included loggers provide a mechanism for composing these, so top level formats like dev_formatter, apache_common and apache_combined are composed in terms of component formatters like formatters::method, formatters::ip, formatters::timestamp, and many others (see formatters for a full list)

When implementing this trait, note that Display::fmt is called on LogFormatter::Output after the response has been fully sent, but that the LogFormatter::format is called before the response has been sent. If you need to perform timing-sensitive calculations that represent the full http cycle, move whatever data is needed to make the calculation into a new type that implements Display, ensuring that it is calculated at the right time.

Implementations

Tuples

LogFormatter is implemented for all tuples of other LogFormatter types, from 2-26 formatters long. The output of these formatters is concatenated with no space between.

&'static str

LogFormatter is implemented for &’static str, allowing for interspersing spaces and other static formatting details into tuples.

use trillium_logger::{Logger, formatters};
let handler = Logger::new()
    .with_formatter(("-> ", formatters::method, " ", formatters::url));

Fn(&Conn, bool) -> impl Display

LogFormatter is implemented for all functions that conform to this signature.

fn user(conn: &Conn, color: bool) -> Cow<'static, str> {
     match conn.state::<User>() {
        Some(user) => String::from(user.name()).into(),
        None => "guest".into()
    }
}

let handler = Logger::new().with_formatter((dev_formatter, " ", user));

Required Associated Types§

source

type Output: Display + Send + Sync + 'static

The display type for this formatter

For a simple formatter, this will likely be a String, or even better, a lightweight type that implements Display.

Required Methods§

source

fn format(&self, conn: &Conn, color: bool) -> Self::Output

Extract Output from this Conn

Implementations on Foreign Types§

source§

impl LogFormatter for &'static str

§

type Output = &'static str

source§

fn format(&self, _conn: &Conn, _color: bool) -> Self::Output

source§

impl LogFormatter for Arc<str>

§

type Output = Arc<str>

source§

fn format(&self, _conn: &Conn, _color: bool) -> Self::Output

source§

impl LogFormatter for ColoredString

§

type Output = String

source§

fn format(&self, _conn: &Conn, color: bool) -> Self::Output

source§

impl<A, B> LogFormatter for (A, B)

§

type Output = TupleOutput<(<A as LogFormatter>::Output, <B as LogFormatter>::Output)>

source§

fn format(&self, conn: &Conn, color: bool) -> Self::Output

source§

impl<A, B, C> LogFormatter for (A, B, C)

§

type Output = TupleOutput<(<A as LogFormatter>::Output, <B as LogFormatter>::Output, <C as LogFormatter>::Output)>

source§

fn format(&self, conn: &Conn, color: bool) -> Self::Output

source§

impl<A, B, C, D> LogFormatter for (A, B, C, D)

§

type Output = TupleOutput<(<A as LogFormatter>::Output, <B as LogFormatter>::Output, <C as LogFormatter>::Output, <D as LogFormatter>::Output)>

source§

fn format(&self, conn: &Conn, color: bool) -> Self::Output

source§

impl<A, B, C, D, E> LogFormatter for (A, B, C, D, E)

§

type Output = TupleOutput<(<A as LogFormatter>::Output, <B as LogFormatter>::Output, <C as LogFormatter>::Output, <D as LogFormatter>::Output, <E as LogFormatter>::Output)>

source§

fn format(&self, conn: &Conn, color: bool) -> Self::Output

source§

impl<A, B, C, D, E, F> LogFormatter for (A, B, C, D, E, F)

§

type Output = TupleOutput<(<A as LogFormatter>::Output, <B as LogFormatter>::Output, <C as LogFormatter>::Output, <D as LogFormatter>::Output, <E as LogFormatter>::Output, <F as LogFormatter>::Output)>

source§

fn format(&self, conn: &Conn, color: bool) -> Self::Output

source§

impl<A, B, C, D, E, F, G> LogFormatter for (A, B, C, D, E, F, G)

§

type Output = TupleOutput<(<A as LogFormatter>::Output, <B as LogFormatter>::Output, <C as LogFormatter>::Output, <D as LogFormatter>::Output, <E as LogFormatter>::Output, <F as LogFormatter>::Output, <G as LogFormatter>::Output)>

source§

fn format(&self, conn: &Conn, color: bool) -> Self::Output

source§

impl<A, B, C, D, E, F, G, H> LogFormatter for (A, B, C, D, E, F, G, H)

§

type Output = TupleOutput<(<A as LogFormatter>::Output, <B as LogFormatter>::Output, <C as LogFormatter>::Output, <D as LogFormatter>::Output, <E as LogFormatter>::Output, <F as LogFormatter>::Output, <G as LogFormatter>::Output, <H as LogFormatter>::Output)>

source§

fn format(&self, conn: &Conn, color: bool) -> Self::Output

source§

impl<A, B, C, D, E, F, G, H, I> LogFormatter for (A, B, C, D, E, F, G, H, I)

§

type Output = TupleOutput<(<A as LogFormatter>::Output, <B as LogFormatter>::Output, <C as LogFormatter>::Output, <D as LogFormatter>::Output, <E as LogFormatter>::Output, <F as LogFormatter>::Output, <G as LogFormatter>::Output, <H as LogFormatter>::Output, <I as LogFormatter>::Output)>

source§

fn format(&self, conn: &Conn, color: bool) -> Self::Output

source§

impl<A, B, C, D, E, F, G, H, I, J> LogFormatter for (A, B, C, D, E, F, G, H, I, J)

§

type Output = TupleOutput<(<A as LogFormatter>::Output, <B as LogFormatter>::Output, <C as LogFormatter>::Output, <D as LogFormatter>::Output, <E as LogFormatter>::Output, <F as LogFormatter>::Output, <G as LogFormatter>::Output, <H as LogFormatter>::Output, <I as LogFormatter>::Output, <J as LogFormatter>::Output)>

source§

fn format(&self, conn: &Conn, color: bool) -> Self::Output

source§

impl<A, B, C, D, E, F, G, H, I, J, K> LogFormatter for (A, B, C, D, E, F, G, H, I, J, K)

§

type Output = TupleOutput<(<A as LogFormatter>::Output, <B as LogFormatter>::Output, <C as LogFormatter>::Output, <D as LogFormatter>::Output, <E as LogFormatter>::Output, <F as LogFormatter>::Output, <G as LogFormatter>::Output, <H as LogFormatter>::Output, <I as LogFormatter>::Output, <J as LogFormatter>::Output, <K as LogFormatter>::Output)>

source§

fn format(&self, conn: &Conn, color: bool) -> Self::Output

source§

impl<A, B, C, D, E, F, G, H, I, J, K, L> LogFormatter for (A, B, C, D, E, F, G, H, I, J, K, L)

§

type Output = TupleOutput<(<A as LogFormatter>::Output, <B as LogFormatter>::Output, <C as LogFormatter>::Output, <D as LogFormatter>::Output, <E as LogFormatter>::Output, <F as LogFormatter>::Output, <G as LogFormatter>::Output, <H as LogFormatter>::Output, <I as LogFormatter>::Output, <J as LogFormatter>::Output, <K as LogFormatter>::Output, <L as LogFormatter>::Output)>

source§

fn format(&self, conn: &Conn, color: bool) -> Self::Output

source§

impl<A, B, C, D, E, F, G, H, I, J, K, L, M> LogFormatter for (A, B, C, D, E, F, G, H, I, J, K, L, M)

§

type Output = TupleOutput<(<A as LogFormatter>::Output, <B as LogFormatter>::Output, <C as LogFormatter>::Output, <D as LogFormatter>::Output, <E as LogFormatter>::Output, <F as LogFormatter>::Output, <G as LogFormatter>::Output, <H as LogFormatter>::Output, <I as LogFormatter>::Output, <J as LogFormatter>::Output, <K as LogFormatter>::Output, <L as LogFormatter>::Output, <M as LogFormatter>::Output)>

source§

fn format(&self, conn: &Conn, color: bool) -> Self::Output

source§

impl<A, B, C, D, E, F, G, H, I, J, K, L, M, N> LogFormatter for (A, B, C, D, E, F, G, H, I, J, K, L, M, N)

§

type Output = TupleOutput<(<A as LogFormatter>::Output, <B as LogFormatter>::Output, <C as LogFormatter>::Output, <D as LogFormatter>::Output, <E as LogFormatter>::Output, <F as LogFormatter>::Output, <G as LogFormatter>::Output, <H as LogFormatter>::Output, <I as LogFormatter>::Output, <J as LogFormatter>::Output, <K as LogFormatter>::Output, <L as LogFormatter>::Output, <M as LogFormatter>::Output, <N as LogFormatter>::Output)>

source§

fn format(&self, conn: &Conn, color: bool) -> Self::Output

source§

impl<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O> LogFormatter for (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O)

§

type Output = TupleOutput<(<A as LogFormatter>::Output, <B as LogFormatter>::Output, <C as LogFormatter>::Output, <D as LogFormatter>::Output, <E as LogFormatter>::Output, <F as LogFormatter>::Output, <G as LogFormatter>::Output, <H as LogFormatter>::Output, <I as LogFormatter>::Output, <J as LogFormatter>::Output, <K as LogFormatter>::Output, <L as LogFormatter>::Output, <M as LogFormatter>::Output, <N as LogFormatter>::Output, <O as LogFormatter>::Output)>

source§

fn format(&self, conn: &Conn, color: bool) -> Self::Output

source§

impl<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P> LogFormatter for (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P)

§

type Output = TupleOutput<(<A as LogFormatter>::Output, <B as LogFormatter>::Output, <C as LogFormatter>::Output, <D as LogFormatter>::Output, <E as LogFormatter>::Output, <F as LogFormatter>::Output, <G as LogFormatter>::Output, <H as LogFormatter>::Output, <I as LogFormatter>::Output, <J as LogFormatter>::Output, <K as LogFormatter>::Output, <L as LogFormatter>::Output, <M as LogFormatter>::Output, <N as LogFormatter>::Output, <O as LogFormatter>::Output, <P as LogFormatter>::Output)>

source§

fn format(&self, conn: &Conn, color: bool) -> Self::Output

source§

impl<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q> LogFormatter for (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q)

§

type Output = TupleOutput<(<A as LogFormatter>::Output, <B as LogFormatter>::Output, <C as LogFormatter>::Output, <D as LogFormatter>::Output, <E as LogFormatter>::Output, <F as LogFormatter>::Output, <G as LogFormatter>::Output, <H as LogFormatter>::Output, <I as LogFormatter>::Output, <J as LogFormatter>::Output, <K as LogFormatter>::Output, <L as LogFormatter>::Output, <M as LogFormatter>::Output, <N as LogFormatter>::Output, <O as LogFormatter>::Output, <P as LogFormatter>::Output, <Q as LogFormatter>::Output)>

source§

fn format(&self, conn: &Conn, color: bool) -> Self::Output

source§

impl<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R> LogFormatter for (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R)

§

type Output = TupleOutput<(<A as LogFormatter>::Output, <B as LogFormatter>::Output, <C as LogFormatter>::Output, <D as LogFormatter>::Output, <E as LogFormatter>::Output, <F as LogFormatter>::Output, <G as LogFormatter>::Output, <H as LogFormatter>::Output, <I as LogFormatter>::Output, <J as LogFormatter>::Output, <K as LogFormatter>::Output, <L as LogFormatter>::Output, <M as LogFormatter>::Output, <N as LogFormatter>::Output, <O as LogFormatter>::Output, <P as LogFormatter>::Output, <Q as LogFormatter>::Output, <R as LogFormatter>::Output)>

source§

fn format(&self, conn: &Conn, color: bool) -> Self::Output

source§

impl<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S> LogFormatter for (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S)

§

type Output = TupleOutput<(<A as LogFormatter>::Output, <B as LogFormatter>::Output, <C as LogFormatter>::Output, <D as LogFormatter>::Output, <E as LogFormatter>::Output, <F as LogFormatter>::Output, <G as LogFormatter>::Output, <H as LogFormatter>::Output, <I as LogFormatter>::Output, <J as LogFormatter>::Output, <K as LogFormatter>::Output, <L as LogFormatter>::Output, <M as LogFormatter>::Output, <N as LogFormatter>::Output, <O as LogFormatter>::Output, <P as LogFormatter>::Output, <Q as LogFormatter>::Output, <R as LogFormatter>::Output, <S as LogFormatter>::Output)>

source§

fn format(&self, conn: &Conn, color: bool) -> Self::Output

source§

impl<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T> LogFormatter for (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T)

§

type Output = TupleOutput<(<A as LogFormatter>::Output, <B as LogFormatter>::Output, <C as LogFormatter>::Output, <D as LogFormatter>::Output, <E as LogFormatter>::Output, <F as LogFormatter>::Output, <G as LogFormatter>::Output, <H as LogFormatter>::Output, <I as LogFormatter>::Output, <J as LogFormatter>::Output, <K as LogFormatter>::Output, <L as LogFormatter>::Output, <M as LogFormatter>::Output, <N as LogFormatter>::Output, <O as LogFormatter>::Output, <P as LogFormatter>::Output, <Q as LogFormatter>::Output, <R as LogFormatter>::Output, <S as LogFormatter>::Output, <T as LogFormatter>::Output)>

source§

fn format(&self, conn: &Conn, color: bool) -> Self::Output

source§

impl<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U> LogFormatter for (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U)

§

type Output = TupleOutput<(<A as LogFormatter>::Output, <B as LogFormatter>::Output, <C as LogFormatter>::Output, <D as LogFormatter>::Output, <E as LogFormatter>::Output, <F as LogFormatter>::Output, <G as LogFormatter>::Output, <H as LogFormatter>::Output, <I as LogFormatter>::Output, <J as LogFormatter>::Output, <K as LogFormatter>::Output, <L as LogFormatter>::Output, <M as LogFormatter>::Output, <N as LogFormatter>::Output, <O as LogFormatter>::Output, <P as LogFormatter>::Output, <Q as LogFormatter>::Output, <R as LogFormatter>::Output, <S as LogFormatter>::Output, <T as LogFormatter>::Output, <U as LogFormatter>::Output)>

source§

fn format(&self, conn: &Conn, color: bool) -> Self::Output

source§

impl<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V> LogFormatter for (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V)

§

type Output = TupleOutput<(<A as LogFormatter>::Output, <B as LogFormatter>::Output, <C as LogFormatter>::Output, <D as LogFormatter>::Output, <E as LogFormatter>::Output, <F as LogFormatter>::Output, <G as LogFormatter>::Output, <H as LogFormatter>::Output, <I as LogFormatter>::Output, <J as LogFormatter>::Output, <K as LogFormatter>::Output, <L as LogFormatter>::Output, <M as LogFormatter>::Output, <N as LogFormatter>::Output, <O as LogFormatter>::Output, <P as LogFormatter>::Output, <Q as LogFormatter>::Output, <R as LogFormatter>::Output, <S as LogFormatter>::Output, <T as LogFormatter>::Output, <U as LogFormatter>::Output, <V as LogFormatter>::Output)>

source§

fn format(&self, conn: &Conn, color: bool) -> Self::Output

source§

impl<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W> LogFormatter for (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W)

§

type Output = TupleOutput<(<A as LogFormatter>::Output, <B as LogFormatter>::Output, <C as LogFormatter>::Output, <D as LogFormatter>::Output, <E as LogFormatter>::Output, <F as LogFormatter>::Output, <G as LogFormatter>::Output, <H as LogFormatter>::Output, <I as LogFormatter>::Output, <J as LogFormatter>::Output, <K as LogFormatter>::Output, <L as LogFormatter>::Output, <M as LogFormatter>::Output, <N as LogFormatter>::Output, <O as LogFormatter>::Output, <P as LogFormatter>::Output, <Q as LogFormatter>::Output, <R as LogFormatter>::Output, <S as LogFormatter>::Output, <T as LogFormatter>::Output, <U as LogFormatter>::Output, <V as LogFormatter>::Output, <W as LogFormatter>::Output)>

source§

fn format(&self, conn: &Conn, color: bool) -> Self::Output

source§

impl<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X> LogFormatter for (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X)

§

type Output = TupleOutput<(<A as LogFormatter>::Output, <B as LogFormatter>::Output, <C as LogFormatter>::Output, <D as LogFormatter>::Output, <E as LogFormatter>::Output, <F as LogFormatter>::Output, <G as LogFormatter>::Output, <H as LogFormatter>::Output, <I as LogFormatter>::Output, <J as LogFormatter>::Output, <K as LogFormatter>::Output, <L as LogFormatter>::Output, <M as LogFormatter>::Output, <N as LogFormatter>::Output, <O as LogFormatter>::Output, <P as LogFormatter>::Output, <Q as LogFormatter>::Output, <R as LogFormatter>::Output, <S as LogFormatter>::Output, <T as LogFormatter>::Output, <U as LogFormatter>::Output, <V as LogFormatter>::Output, <W as LogFormatter>::Output, <X as LogFormatter>::Output)>

source§

fn format(&self, conn: &Conn, color: bool) -> Self::Output

source§

impl<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y> LogFormatter for (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y)

§

type Output = TupleOutput<(<A as LogFormatter>::Output, <B as LogFormatter>::Output, <C as LogFormatter>::Output, <D as LogFormatter>::Output, <E as LogFormatter>::Output, <F as LogFormatter>::Output, <G as LogFormatter>::Output, <H as LogFormatter>::Output, <I as LogFormatter>::Output, <J as LogFormatter>::Output, <K as LogFormatter>::Output, <L as LogFormatter>::Output, <M as LogFormatter>::Output, <N as LogFormatter>::Output, <O as LogFormatter>::Output, <P as LogFormatter>::Output, <Q as LogFormatter>::Output, <R as LogFormatter>::Output, <S as LogFormatter>::Output, <T as LogFormatter>::Output, <U as LogFormatter>::Output, <V as LogFormatter>::Output, <W as LogFormatter>::Output, <X as LogFormatter>::Output, <Y as LogFormatter>::Output)>

source§

fn format(&self, conn: &Conn, color: bool) -> Self::Output

source§

impl<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z> LogFormatter for (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z)

§

type Output = TupleOutput<(<A as LogFormatter>::Output, <B as LogFormatter>::Output, <C as LogFormatter>::Output, <D as LogFormatter>::Output, <E as LogFormatter>::Output, <F as LogFormatter>::Output, <G as LogFormatter>::Output, <H as LogFormatter>::Output, <I as LogFormatter>::Output, <J as LogFormatter>::Output, <K as LogFormatter>::Output, <L as LogFormatter>::Output, <M as LogFormatter>::Output, <N as LogFormatter>::Output, <O as LogFormatter>::Output, <P as LogFormatter>::Output, <Q as LogFormatter>::Output, <R as LogFormatter>::Output, <S as LogFormatter>::Output, <T as LogFormatter>::Output, <U as LogFormatter>::Output, <V as LogFormatter>::Output, <W as LogFormatter>::Output, <X as LogFormatter>::Output, <Y as LogFormatter>::Output, <Z as LogFormatter>::Output)>

source§

fn format(&self, conn: &Conn, color: bool) -> Self::Output

Implementors§

source§

impl<F, O> LogFormatter for F
where F: Fn(&Conn, bool) -> O + Send + Sync + 'static, O: Display + Send + Sync + 'static,

§

type Output = O