a logging engine backend of Apple's swift-log

What's New




a logging engine backend of Apple's swift-log


Swift5.0+ release Build codecov license



  • Pure Swift
  • Backend of apple/swift-log
  • Both Darwin(iOS macOS watchOS tvOS) and Linux compatibility
  • Builtin output target : [stdout/stderr,file,oslog,syslog]
  • ANSI escape code
  • Complete customizable for text out
  • Support string interpolation the same as Apple's Unified Logging System
  • 100% Code Coverage


Use Builtin Sinks

Simple stdout

//create sink
let sink = StandardSink.out()
//create formation
let formation = Formation.standard
//create log
var logger = Logger(label: "LogName") {
    Handler(name: $0, sink: sink, formation: formation, logLevel: .trace)
// do some logs
logger.trace("This is a trace message")
logger.debug("This is a debug message")"This is a info message")
logger.notice("This is a notice message")
logger.warning("This is a warning message")
logger.error("This is a error message")
logger.critical("This is a critical message")

Terminal out :

Change LogLevel

logger.logLevel = .info
logger.debug("will not log")"will log")

Add MetaData

logger[metadataKey: "UserID"] = .stringConvertible(9527)"message with logger meta data")"message with both logger and message meta data", metadata: ["UserName": .string("L1MeN9Yu")])

Terminal out :

Builtin Sinks


let fileSink = FileSink("path/of/log")

Log message will write to file.

See Tests for more.

OSLogSink (Apple platform only)

let osLogSink = OSLogSink(subsystem: "subsystem", category: "category")

Log message will write to OS log (Apple's syslog). Use in your macOS to watch oslog messages.

See Tests for more.

SystemLogSink (Linux)

let systemLogSink = SystemLogSink()

Log message will write to syslog.

See Tests for more.


Formation generate the log message.

There are some builtin Formation:

  1. Formation.standard. This is default for stdout/stderr.
  2. Formation.standardXcode. This is default for stdout/stderr display in Xcode due Xcode's console is not support ANSI escape code.
  3. Formation.file. This is default for File.
  4. Formation.os. This is default for OSLog.
  5. Formation.system. This is default for syslog.

Advanced Customize Formation

Create Formation is simple : Formation(components: <#T##[Component]##[Senna.Component]#>, printer: <#T##Printable?##Senna.Printable?#>, separator: <#T##String?##Swift.String?#>)

The Formation contains components: [Component], printer: Printable? and separator: String?.


Component is your log message's element. See Component file.


The Printable enhanced your log messages, It can add color or style to the component.

The builtin Printer has two default instance. Printer.standard for stdout/stderr. Printer.xcode for stdout/stderr in Xcode.

You can create new Printer instance or Use YourPrinter which implements Printable protocol.

See Printer and Printable for more.


The Separator string is used for split log message's component. The Formation.standard's separator is " ▶ ".

Apple's Unified Logging System

Senna reimplement the string interpolation behavior of Apple's Unified Logging System

let sink = StandardSink.out()
let formation = Formation.standard
var logger = Logger(label: "LogName") {
    Handler(name: $0, sink: sink, formation: formation, logLevel: .trace)
logger[metadataKey: "UserID"] = .stringConvertible(9527)
let privacy = Privacy.public
let privacy = Privacy.private
// default is private
logger.senna.notice("the user name is \("L1MeN9Yu")")
logger.senna.notice("the user name is \("L1MeN9Yu", privacy: privacy)")

Terminal out :

see LoggerSennaTests.swift for more usages.


Swift Package Manager

Add the following to your Package.swift file:

dependencies: [
    .package(url: "", from: "3.0.0")



Senna is available under the MIT license. See the LICENSE file for details.

Thanks | 鸣谢

Thanks to JetBrains for "Licenses for Open Source Development". JetBrains supports non-commercial open source projects by providing core project contributors with a set of best-in-class developer tools free of charge.

感谢 JetBrains 提供的开源开发许可证。JetBrains 通过为项目核心开发者免费提供开发工具来支持非商业开源项目。


  • Swift Tools 5.2.0
View More Packages from this Author


Last updated: Fri Apr 05 2024 09:41:40 GMT-0900 (Hawaii-Aleutian Daylight Time)