UCILoader 1.1.2
Small C++ library that allows user to connect to a chess engines via UCI protocol.
Loading...
Searching...
No Matches
UCILoader::LoggerBuilder Class Reference

Builder class for constructing and composing loggers with traits. More...

#include <Logger.h>

Public Member Functions

 LoggerBuilder (std::unique_ptr< Logger > &&base)
 Construct a LoggerBuilder with a base logger.
 
 LoggerBuilder (LoggerBuilder &&other)
 Move constructor.
 
LoggerBuilderaddTrait (const LoggerTrait &trait)
 Add a trait to customize the logger behavior.
 
std::unique_ptr< Loggerbuild ()
 Build and return the final logger instance.
 

Friends

LoggerBuilder operator| (LoggerBuilder builder, const LoggerTrait &trait)
 Operator overload for applying traits using pipe operator.
 

Detailed Description

Builder class for constructing and composing loggers with traits.

LoggerBuilder provides a fluent interface for creating loggers with custom behavior. Loggers are created using factory functions in the Loggers namespace, then composed with traits using the pipe operator (|).

The builder uses the pipe operator for readability and to allow chaining multiple trait applications. Once all traits are applied, call build() to obtain the final logger instance.

See also
Loggers namespace for factory functions
LoggerTraits namespace for available traits

Usage Examples:

// Simple file logger
auto logger1 = Loggers::toFile("debug.log").build();
// File logger with Pretty formatting
auto logger2 = (Loggers::toFile("debug.log") | LoggerTraits::Pretty).build();
// File logger with Pretty formatting and timestamps
auto logger3 = (Loggers::toFile("debug.log")
// Logger that ignores parser messages
auto logger4 = (Loggers::toFile("engine.log")
std::unique_ptr< Logger > build()
Build and return the final logger instance.
Definition: Logger.cpp:227
const LoggerTrait & Timestamp
Trait that prepends timestamps to all logged messages.
Definition: Logger.cpp:169
const LoggerTrait & IgnoreParser
Trait that filters out messages generated by the parser.
Definition: Logger.cpp:166
const LoggerTrait & Pretty
Trait that formats log messages for human readability.
Definition: Logger.cpp:165
LoggerBuilder toFile(const std::string &filename)
Create a logger that outputs to a file.
Definition: Logger.cpp:185

Constructor & Destructor Documentation

◆ LoggerBuilder() [1/2]

UCILoader::LoggerBuilder::LoggerBuilder ( std::unique_ptr< Logger > &&  base)

Construct a LoggerBuilder with a base logger.

Parameters
baseThe base logger instance

◆ LoggerBuilder() [2/2]

UCILoader::LoggerBuilder::LoggerBuilder ( LoggerBuilder &&  other)

Move constructor.

Parameters
otherThe LoggerBuilder to move from

Member Function Documentation

◆ addTrait()

LoggerBuilder & UCILoader::LoggerBuilder::addTrait ( const LoggerTrait trait)

Add a trait to customize the logger behavior.

This method applies a trait by wrapping the current logger. Traits are applied in the order they are added.

Parameters
traitThe trait to add
Returns
Reference to this builder for method chaining

◆ build()

std::unique_ptr< Logger > UCILoader::LoggerBuilder::build ( )

Build and return the final logger instance.

Returns
A unique_ptr to the fully configured Logger

Friends And Related Function Documentation

◆ operator|

LoggerBuilder operator| ( LoggerBuilder  builder,
const LoggerTrait trait 
)
friend

Operator overload for applying traits using pipe operator.

This allows fluent syntax using the | operator:

auto logger = Loggers::toFile("log.txt") | LoggerTraits::Pretty;
Parameters
builderThe logger builder
traitThe trait to apply
Returns
The modified builder

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