ModErn Text Analysis
META Enumerates Textual Applications
Public Types | Public Member Functions | Static Public Member Functions | Private Attributes | List of all members
meta::logging::logger::sink Class Reference

sink: A wrapper for a stream that a logger should write to. More...

#include <logger.h>

Public Types

using formatter_func = std::function< std::string(const log_line &)>
 Convenience typedef for functions that format log lines.
 
using filter_func = std::function< bool(const log_line &)>
 Convenience typedef for functions that filter log lines.
 

Public Member Functions

 sink (std::ostream &stream, const filter_func &filter=[](const log_line &){return true;}, const formatter_func &formatter=&default_formatter)
 Creates a new sink with the given formatting function and filtering function. More...
 
 sink (std::ostream &stream, logger::severity_level sev, const formatter_func &formatter=&default_formatter)
 Creates a new sink on the given stream, filtering out all results that are greater than or equal to the specified severity, using the provided formatting function. More...
 
void write (const log_line &line)
 Writes the given log_line to the stream, formatting and filtering it as necessary. More...
 

Static Public Member Functions

static std::string default_formatter (const log_line &line)
 The default formatting function. More...
 

Private Attributes

std::ostream & stream_
 Internal stream.
 
formatter_func formatter_
 The formatting functor.
 
filter_func filter_
 The filtering functor.
 

Detailed Description

sink: A wrapper for a stream that a logger should write to.

Constructor & Destructor Documentation

meta::logging::logger::sink::sink ( std::ostream &  stream,
const filter_func filter = [](const log_line&) { return true; },
const formatter_func formatter = &default_formatter 
)
inline

Creates a new sink with the given formatting function and filtering function.

A filtering function should take a log_line by const-reference and determine if it should or should not be written to the stream. If a formatting function is not provided, use a sane default formatter.

Parameters
streamThe stream this sink will write to
formatterThe formatting function object to use to format the log_lines written to the stream
filterThe filtering function used to determine if a given log_line should be written to the stream or not
meta::logging::logger::sink::sink ( std::ostream &  stream,
logger::severity_level  sev,
const formatter_func formatter = &default_formatter 
)
inline

Creates a new sink on the given stream, filtering out all results that are greater than or equal to the specified severity, using the provided formatting function.

If no formatting function is provided, use a sane default.

Parameters
streamThe stream this sink will write to
sevThe severity level at or above which log lines will be kept
formatterThe optional formatting function

Member Function Documentation

void meta::logging::logger::sink::write ( const log_line line)
inline

Writes the given log_line to the stream, formatting and filtering it as necessary.

Parameters
lineThe log_line to be written
static std::string meta::logging::logger::sink::default_formatter ( const log_line line)
inlinestatic

The default formatting function.

Parameters
lineThe log_line to format
Returns
a string representation of the log_line suitable for writing to a std::ostream

The documentation for this class was generated from the following file: