A simple Swift logging library for macOS apps. Log messages at different levels (info, warning, debug, error), control logging globally, and customize subsystem and category for each message.
✅ Four log levels: info, warning, debug, error
✅ Enable or disable all logging with one flag
✅ Default subsystem is your app’s bundle identifier (overrideable)
✅ Default category is "General" (overrideable)
✅ Each log entry includes file name, line number, and function name
- macOS 10.15 or later
- Swift 5.5 or later
- In Xcode, choose File ▸ Add Packages…
- Enter the URL of this repository:
https://github.com/Krusty84/LoggerHelper.git - Select the version (for example, Up to Next Major 1.0.0) and add it to your app target.
- Enable logging early in your app:
import SwiftUI
import LoggerHelper
struct ContentView: View {
@State private var isLoggingEnabled: Bool = false
var body: some View {
VStack(spacing: 20) {
Image(systemName: "globe")
.imageScale(.large)
.foregroundStyle(.tint)
Text("Hello, world!")
.font(.title)
// Toggle to enable/disable logging
Toggle("Enable Logging", isOn: $isLoggingEnabled)
.padding(.horizontal)
.onChange(of: isLoggingEnabled) { newValue in
LoggerHelper.loggingEnabled = newValue
}
// Buttons for each log level
VStack(spacing: 10) {
Button("Info Log") {
LoggerHelper.info("This is an info message")
}
Button("Warning Log") {
LoggerHelper.warning("This is a warning message")
}
Button("Debug Log") {
LoggerHelper.debug("This is a debug message")
}
Button("Error Log") {
LoggerHelper.error("This is an error message")
}
}
.buttonStyle(.borderedProminent)
}
.padding()
.onAppear {
// initialize the helper with the same flag
LoggerHelper.loggingEnabled = isLoggingEnabled
}
}
}-
Log with defaults:
LoggerHelper.info("Hello, world!")
- Uses
Bundle.main.bundleIdentifieras subsystem - Uses
"General"as category
- Uses
-
Log with custom subsystem or category:
LoggerHelper.debug( "User tapped button", subsystem: "com.mycompany.mytool", category: "UI" )
-
Other levels:
LoggerHelper.warning("Low disk space") LoggerHelper.error("Failed to load data")