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/YourUserName/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 (e.g. in
AppDelegate
):import LoggerHelper @main class AppDelegate: NSObject, NSApplicationDelegate { func applicationDidFinishLaunching(_ notification: Notification) { // Turn logging on or off as needed #if DEBUG LoggerHelper.loggingEnabled = true #else LoggerHelper.loggingEnabled = false #endif LoggerHelper.info("App did finish launching") } }
-
Log with defaults:
LoggerHelper.info("Hello, world!")
- Uses
Bundle.main.bundleIdentifier
as 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")