A high-performance logging framework for Apple platforms built on SwiftyBeaver. Lightweight Logger instances share a single engine with CoreData-backed persistence, rotation policies, and built-in SwiftUI/UIKit log viewers.
- Features
- Screenshots
- Compatibility and Installation
- Quick Start
- Advanced Configuration
- Log Viewer UI
- SwiftUI Environment
- Testing
- Example App
- FAQ
- Open Source Collaboration
- License
- Lightweight
Loggervalue type with shared engine across instances - CoreData-backed persistence with size and retention-based rotation
- Console output and database storage can be enabled independently
- Async batched writes with debounce and immediate flush for critical levels
- Automatic context extraction (module name) or custom context
- SwiftUI
Environmentintegration - Built-in log viewer with filtering, search, and export
- Swift 5.9+
- iOS 15+
- macOS 12+
- watchOS 8+
- tvOS 15+
| Package Manager | Supported Platforms |
|---|---|
| Swift Package Manager | iOS / macOS / watchOS / tvOS |
CocoaPods (HMLoggerKit) |
iOS / macOS / watchOS / tvOS |
dependencies: [
.package(url: "https://github.com/HeminWon/LoggerKit.git", from: "0.2.7")
].target(
name: "YourTarget",
dependencies: ["LoggerKit"]
)pod 'HMLoggerKit', '~> 0.2.7'Important: call
LK.configure(...)early during app launch.
import SwiftUI
import LoggerKit
@main
struct MyApp: App {
init() {
LK.configure(level: .debug, enableConsole: true, enableDatabase: true)
}
var body: some Scene {
WindowGroup { ContentView() }
}
}import UIKit
import LoggerKit
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
LK.configure(level: .debug, enableConsole: true, enableDatabase: true)
return true
}
}import LoggerKit
let logger = Logger()
logger.debug("Debug message")
logger.info("Info message")
logger.warning("Warning message")
logger.error("Error message")Use LK.configure(...) for most cases. Use LoggerEngine.configure(...) only when you need fine-grained write behavior control:
import LoggerKit
LoggerEngine.configure(
LoggerEngineConfiguration(
level: .info,
enableConsole: true,
enableDatabase: true,
maxDatabaseSize: 100 * 1024 * 1024,
maxRetentionDays: 30,
batchSize: 50,
debounceInterval: 2.0,
immediateFlushLevels: [.error, .warning]
)
)import SwiftUI
import LoggerKit
struct LogsView: View {
var body: some View {
LK.makeViewWithViewStore()
}
}import UIKit
import LoggerKit
final class HomeViewController: UIViewController {
@objc private func showLogs() {
let vc = LK.makeViewController()
navigationController?.pushViewController(vc, animated: true)
}
}import SwiftUI
import LoggerKit
struct MyView: View {
@Environment(\.logger) private var logger
var body: some View {
Button("Log") { logger.info("Button tapped") }
}
}MockLogger is available in Sources/LoggerKit/Testing for unit tests and logging behavior assertions.
Use the Package.swift-based build script to archive and package a distributable XCFramework:
sh Scripts/build-xcframework-from-package.shOptional arguments:
--scheme LoggerKit--platforms ios,macos,tvos,watchos--output ./artifacts/spm--keep-archives--verify-swiftinterface(默认跳过严格校验以避免部分依赖构建失败)
See Examples/iOS/LoggerKitExample for a full demo.
- Confirm
LK.configure(...)is called during app startup - Confirm the configured log level allows the log you are writing (for example
.infodoes not include.debug) - If only database output is enabled, logs will not appear in the Xcode console
LoggerEngine can be configured only once. Additional calls are ignored (and trigger assertionFailure in DEBUG).
Logs are stored and managed through CoreData. Use the built-in log viewer for browsing and export instead of relying on fixed file paths.
Usually no. Rotation checks are executed asynchronously after startup.
- Contributing guide:
CONTRIBUTING.md - Security policy:
SECURITY.md - Code of conduct:
CODE_OF_CONDUCT.md - Changelog:
CHANGELOG.md
MIT




