A lightweight, flexible logging library for Swift applications that supports multiple logging destinations and privacy levels.
- 🚀 Simple, intuitive API
- 🎯 Multiple logging destinations (Console, OSLog, Firebase)
- 🔒 Privacy-aware logging with configurable sensitivity levels
- 📱 Perfect for iOS, macOS, and Swift Package applications
- 🛠 Extensible architecture through protocol-based design
- 📊 File name and line number tracking
- ⚡️ Zero external dependencies (Firebase integration optional)
Add GoodLogger to your Package.swift
:
dependencies: [
.package(url: "https://github.com/yourusername/GoodLogger.git", from: "1.3.0")
]
import GoodLogger
// Choose your preferred logger
let logger = PrintLogger()
// or
let osLogger = OSLogLogger()
// or
let firebaseLogger = FirebaseLogger(crashlytics: yourCrashlyticsInstance)
// Start logging!
logger.log(message: "Application started")
Simple console logging with automatic file name and line number tracking:
let logger = PrintLogger()
logger.log(message: "Debug message") // Output: [FileName.swift:42] Debug message
Integration with Apple's unified logging system:
let logger = OSLogLogger()
logger.log(message: "User action completed", level: .info)
logger.log(message: "Sensitive data", level: .debug, privacy: .private)
Crashlytics integration through protocol-based design:
// First, conform to CrashlyticsLogging
class MyCrashlytics: CrashlyticsLogging {
func log(_ msg: String) {
// Your implementation
}
}
// Then use it
let firebaseLogger = FirebaseLogger(crashlytics: MyCrashlytics())
firebaseLogger.log(message: "Critical error occurred")
Create your own logger by implementing the GoodLogger
protocol:
struct MyCustomLogger: GoodLogger {
func log(message: String, level: LogLevel = .info, privacy: Privacy = .public) {
// Your custom implementation
}
}
import SwiftUI
import GoodLogger
struct ContentView: View {
private let logger = PrintLogger()
var body: some View {
Button("Log Event") {
logger.log(message: "Button tapped", level: .info)
}
}
}
- Use appropriate log levels (
debug
,info
,error
) for different scenarios - Consider privacy implications when logging sensitive data
- Create a shared logger instance for consistent logging across your app
- Implement custom loggers for specific needs (e.g., network logging, analytics)
We welcome contributions! Here's how you can help:
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature
) - Commit your changes (
git commit -m 'Add AmazingFeature'
) - Push to the branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
GoodLogger is available under the MIT license. See the LICENSE file for more info.
- Create an Issue
- Follow for updates
- Star the repository if you find it useful!