Yet another logger for Swift.
This uses Apple's Unified Logging OSLog
- and NSLog
as a fallback, so it's essentially a façade.
I think this makes OSLog
easier to use in Swift since you can use string interpolation.
I renamed this from GDLog since there is already a Cocoapod with that name.
- iOS 10.0+ / Mac OS X 10.12+ / tvOS 10.0+ / watchOS 3.0+
- Xcode 9.0+
CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:
$ gem install cocoapods
To integrate GDLog into your Xcode project using CocoaPods, specify it in your Podfile
:
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '10.0'
use_frameworks!
pod 'GDLog', '~> 0.0.1'
Then, run the following command:
$ pod install
Carthage is a decentralized dependency manager that automates the process of adding frameworks to your Cocoa application.
You can install Carthage with Homebrew using the following command:
$ brew update
$ brew install carthage
To integrate GDLog into your Xcode project using Carthage, specify it in your Cartfile
:
github "GDLog/GDLog" ~> 0.0.1
To use GDLog as a Swift Package Manager package just add the following in your Package.swift file.
import PackageDescription
let package = Package(
name: "GDLog",
dependencies: [
.Package(url: "https://github.com/genedelisa/GDLog.git", "0.0.1")
]
)
If you prefer not to use either of the aforementioned dependency managers, you can integrate GDLog into your project manually.
- Open up Terminal,
cd
into your top-level project directory, and run the following command "if" your project is not initialized as a git repository:
$ git init
- Add GDLog as a git submodule by running the following command:
$ git submodule add https://github.com/genedelisa/GDLog.git
$ git submodule update --init --recursive
- Open the new
GDLog
folder, and drag theGDLog.xcodeproj
into the Project Navigator of your application's Xcode project.
It should appear nested underneath your application's blue project icon. Whether it is above or below all the other Xcode groups does not matter.
- Select the
GDLog.xcodeproj
in the Project Navigator and verify the deployment target matches that of your application target. - Next, select your application project in the Project Navigator (blue project icon) to navigate to the target configuration window and select the application target under the "Targets" heading in the sidebar.
- In the tab bar at the top of that window, open the "General" panel.
- Click on the
+
button under the "Embedded Binaries" section. - You will see two different
GDLog.xcodeproj
folders each with two different versions of theGDLog.framework
nested inside aProducts
folder.
It does not matter which
Products
folder you choose from.
-
Select the
GDLog.framework
. -
And that's it!
The
GDLog.framework
is automagically added as a target dependency, linked framework and embedded framework in a copy files build phase which is all you need to build on the simulator and a device.
- Download the latest release from https://github.com/genedelisa/GDLog/releases
- Next, select your application project in the Project Navigator (blue project icon) to navigate to the target configuration window and select the application target under the "Targets" heading in the sidebar.
- In the tab bar at the top of that window, open the "General" panel.
- Click on the
+
button under the "Embedded Binaries" section. - Add the downloaded
GDLog.framework
. - And that's it!
To set the logging level for a subsystem.
$ sudo log config --mode "level:debug" --subsystem com.your_company.your_subsystem_name
For example, from the Terminal (or iterm), set the debug level for your subsystem. Then you can stream the output.
$ sudo log config --mode "level:debug" --subsystem com.rockhoppertech.SlowItDown
$ log stream --predicate 'subsystem == "com.rockhoppertech.SlowItDown"' --info --debug
To check the current logging level.
$ sudo log config --status
Use the system console (and/or Xcode's console) to read the logging messages.
You can filter by your subsystem in the Console app.
Sample Console output:
The message emojis can be redefined per level.
var log = GDLog()
log.debugPrefix = "♫ "
log.debugPostfix = " ♫"
Here is some sample output.
2017-12-18 15:54:03.611598-0500 SlowItDown[31758:2620634] [general] 😺😺😺 authorized ☞ checkMediaLibraryPermission() 🗄MediaLibraryController.swift➸121 😺😺😺
Other options for creating loggers.
var log2 = GDLog(category: "my category")
log2.debug("logging to my category string")
public enum MyCategories: String {
case mycat
}
var log3 = GDLog(category: MyCategories.mycat.rawValue)
log3.debug("logging to my category enum")
var log4 = GDLog(.controller, category: .general)
log4.debug("logging to controler subsystem using general category")
GDLog is released under the MIT license. See LICENSE for details.