Enumeration
LoggerFragmentBuilder
A result builder for creating logger fragments in a declarative way.
@resultBuilder enum LoggerFragmentBuilder<let spaces : Int>
Overview
This allows you to build complex logger fragment combinations using Swift’s result builder syntax.
You can add spaces between fragments by specifying the number of spaces as the generic parameter. For example, @LoggerFragmentBuilder<1> will add a single space between fragments, while @LoggerFragmentBuilder<0> will not add any spaces.
Topics
Type Methods
static func buildArray<F>([F]) -> ArrayFragment<F>Build an array of fragments using a customArrayFragment.static func buildBlock() -> LiteralFragmentBuild a block from no fragments (empty block).static func buildBlock<F>(F) -> FBuild a block from a single logger fragment.static func buildEither<F>(first: F) -> FBuild either branch for if-else statements (first branch).static func buildEither<F>(second: F) -> FBuild either branch for if-else statements (second branch).static buildExpression(_:)Build an expression from a string literal, creating aLiteralFragment.static func buildOptional<F>(F?) -> OptionalFragment<F>Handle optional fragments using an optional wrapper.static func buildPartialBlock<F1, F2>(accumulated: F1, next: F2) -> AndFragment<F1, SeparatorFragment<F2>>Combine accumulated fragments with the next fragment usingAndFragment.static func buildPartialBlock<F>(first: F) -> FBuild the first fragment in a partial block.
See Also
Logger Fragments
protocol LoggerFragmentA fragment of a log message.struct FragmentOutputThe output of aLoggerFragment, including some intermediary state used for things like deduplicating separators.struct IfMaxLevelFragmentMake the current fragment conditional, only calling itsoutputmethod if the record’sloggerLevelismaxLevelor lowerstruct AndFragmentCombine the current fragment with another, which will be written after the current fragment finishes.struct OptionalFragmentA fragment that conditionally includes another fragment.struct ArrayFragmentA fragment that combines multiple fragments of the same type.struct LabelFragmentWrites the label of the logger, and requests a separator for the next fragment.struct LevelFragmentWrites the level of the logged message, and requests a separator for the next fragment.struct LiteralFragmentWrites the given text to the output.struct SeparatorFragmentstruct SpacedFragmentA fragment that wraps another fragment, automatically separating its components with spaces.struct MessageFragmentWrites the logged message to the output, and requests a separator for the next fragment.struct MetadataFragmentWrites the combined metadata to the output, and requests a separator for the next fragment only if the metadata was not empty.struct SourceLocationFragmentWrites the file location of the logged message, including the line.struct LoggerSourceFragmentWrites the source of the logged message.