javiermanzo/logbird
LogBird is a powerful yet simple logging library for Swift, designed to provide flexible and efficient console logging.
Table of Contents
- CocoaPods - Swift Package Manager
- Log Levels - Static Logging - Instance Logging - Log Parameters - Combine Support - SwiftUI View
Features
- [x] Static logging via
LogBirdmethods - [x] Custom logging instances
- [x] Multiple log levels
- [x] Customizable log identifier
- [x] Combine support via
logsPublisher - [x] SwiftUI
LBLogsViewfor log visualization
Requirements
- Swift 5.9+
- iOS 15.0+
Installation
You can add LogBird to your project using CocoaPods or Swift Package Manager.
CocoaPods
Add the following line to your Podfile:
pod 'LogBird'Swift Package Manager
Add the following to your Package.swift file:
dependencies: [
.package(url: "https://github.com/javiermanzo/LogBird.git")
]Usage
Log Levels
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.
Static Logging
Use the static methods provided by LogBird for simple logging:
LogBird.log(message: "This is an info log")Instance Logging
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")Log Parameters
The log method supports additional parameters for more detailed logs.
Logging with extra messages:
let extraMessages: [LBExtraMessage] = [
LBExtraMessage(title: "Title extra", message: "Message extra")
]
LogBird.log("My Log",
extraMessages: extraMessages)Logging with additional info:
LogBird.log("Purchase",
additionalInfo: ["userId": 12, "planId": 2],
level: .info)Logging an error:
let someError = NSError(
domain: "com.myapp.error",
code: 500,
userInfo: [NSLocalizedDescriptionKey: "Error description"]
)
LogBird.log("Log Error",
error: someError,
level: .error)Combine Support
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)SwiftUI View
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"))
}
}Contributing
If you encounter any issues, please submit an issue. Pull requests are also welcome!
License
LogBird is available under the MIT license. See the LICENSE file for more info.
Package Metadata
Repository: javiermanzo/logbird
Default branch: main
README: README.md