LogBird is a powerful yet simple logging library for Swift, designed to provide flexible and efficient console logging.
- Static logging via
LogBirdmethods - Custom logging instances
- Multiple log levels
- Customizable log identifier
- Combine support via
logsPublisher - SwiftUI
LBLogsViewfor log visualization
- Swift 5.9+
- iOS 15.0+
You can add LogBird to your project using CocoaPods or Swift Package Manager.
Add the following line to your Podfile:
pod 'LogBird'Add the following to your Package.swift file:
dependencies: [
.package(url: "https://github.com/javiermanzo/LogBird.git")
]LogBird supports the following log levels via the LBLogLevel enum:
.debug: For debugging information..info: For informational messages..warning: For warnings..error: For error messages..critical: For critical issues.
Use the static methods provided by LogBird for simple logging:
LogBird.log(message: "This is an info log")Create a custom instance of LogBird for more flexibility:
let customLogger = LogBird(subsystem: "com.example.myapp", category: "Network")
customLogger.log(message: "This is a debug log from the Network category")The log method supports additional parameters for more detailed logs.
let extraMessages: [LBExtraMessage] = [
LBExtraMessage(title: "Title extra", message: "Message extra")
]
LogBird.log("My Log",
extraMessages: extraMessages)LogBird.log("Purchase",
additionalInfo: ["userId": 12, "planId": 2],
level: .info)let someError = NSError(
domain: "com.myapp.error",
code: 500,
userInfo: [NSLocalizedDescriptionKey: "Error description"]
)
LogBird.log("Log Error",
error: someError,
level: .error)Access logs using Combine to react to new logs in real time:
import Combine
var logs: [LBLog] = []
var subscribers = Set<AnyCancellable>()
let logBird = LogBird(subsystem: "com.example.myapp", category: "UI")
LogBird.logsPublisher
.receive(on: DispatchQueue.main)
.sink { [weak self] newLogs in
self?.logs = newLogs
}
.store(in: &subscribers)Use LBLogsView to visualize logs in your app. You can optionally provide a custom LogBird instance; by default, it uses the static instance:
import SwiftUI
struct ContentView: View {
var body: some View {
LBLogsView(logBird: LogBird(subsystem: "com.example.myapp", category: "UI"))
}
}If you encounter any issues, please submit an issue. Pull requests are also welcome!
LogBird was created by Javier Manzo.
LogBird is available under the MIT license. See the LICENSE file for more info.
