Package
ConsoleLogger
A
SwiftLog LogHandler implementation for customizable logging to a console.Overview
ConsoleLogger is a flexible logging backend for console applications, allowing developers to customize log output with various fragments, including timestamps, log levels, and source locations.
Topics
Essentials
- Getting Started with ConsoleLoggerCustomize your logging output in Swift console applications using
ConsoleLogger, a flexibleSwiftLogbackend. struct ConsoleLoggerOutputs logs to console via aLoggerFragmentpipeline.
Logger Fragments
protocol LoggerFragmentA fragment of a log message.enum LoggerFragmentBuilderA result builder for creating logger fragments in a declarative way.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.protocol TimestampSourceA protocol to allow mocking the timestamp for testsstruct SystemTimestampSourceThe defaultTimestampSource, which gets the time from the system.struct TimestampFragmentWrites a formatted timestamp based on the time obtained from theTimestampSource.typealias DefaultLoggerFragmentTypeThe type of the defaultLoggerFragment.typealias TimestampDefaultLoggerFragmentTypeThe type of the defaultLoggerFragmentwith a timestamp.
Miscellaneous
struct LogRecordInformation about a specific log message, including information from the logger the message was logged to.protocol ConsoleLoggerPrinterDefines a printer used by aConsoleLoggerto output log messages.struct DefaultConsoleLoggerPrinterThe defaultConsoleLoggerPrinterthat prints to standard output.