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.
### Swift Package Manager
To use GDLog as a [Swift Package Manager](https://swift.org/package-manager/) package just add the following in your Package.swift file.
``` swift
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.
cd
into your top-level project directory, and run the following command "if" your project is not initialized as a git repository:$ git init
$ git submodule add https://github.com/genedelisa/GDLog.git
$ git submodule update --init --recursive
GDLog
folder, and drag the GDLog.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.
GDLog.xcodeproj
in the Project Navigator and verify the deployment target matches that of your application target.+
button under the "Embedded Binaries" section.GDLog.xcodeproj
folders each with two different versions of the GDLog.framework
nested inside a Products
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.
+
button under the "Embedded Binaries" section.GDLog.framework
.The SPM itself has a good logger.
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.
link |
Stars: 0 |
Last commit: 4 years ago |
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics