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
buildArray(_:)Build an array of fragments using a customArrayFragment.buildBlock()Build a block from no fragments (empty block).buildBlock(_:)Build a block from a single logger fragment.buildEither(first:)Build either branch for if-else statements (first branch).buildEither(second:)Build either branch for if-else statements (second branch).buildExpression(_:)Build an expression from a string literal, creating aLiteralFragment.buildOptional(_:)Handle optional fragments using an optional wrapper.buildPartialBlock(accumulated:next:)Combine accumulated fragments with the next fragment usingAndFragment.buildPartialBlock(first:)Build the first fragment in a partial block.
See Also
Logger Fragments
LoggerFragmentA fragment of a log message.FragmentOutputThe output of aLoggerFragment, including some intermediary state used for things like deduplicating separators.IfMaxLevelFragmentMake the current fragment conditional, only calling itsoutputmethod if the record’sloggerLevelismaxLevelor lowerAndFragmentCombine the current fragment with another, which will be written after the current fragment finishes.OptionalFragmentA fragment that conditionally includes another fragment.ArrayFragmentA fragment that combines multiple fragments of the same type.LabelFragmentWrites the label of the logger, and requests a separator for the next fragment.LevelFragmentWrites the level of the logged message, and requests a separator for the next fragment.LiteralFragmentWrites the given text to the output.SeparatorFragmentSpacedFragmentA fragment that wraps another fragment, automatically separating its components with spaces.MessageFragmentWrites the logged message to the output, and requests a separator for the next fragment.MetadataFragmentWrites the combined metadata to the output, and requests a separator for the next fragment only if the metadata was not empty.SourceLocationFragmentWrites the file location of the logged message, including the line.LoggerSourceFragmentWrites the source of the logged message.