Alternatively navigate to your Xcode project, select Swift Packages and click the + icon to search for LoggingKit.
Manually
If you prefer not to use any of the aforementioned dependency managers, you can integrate LoggingKit into your project manually. Simply drag the Sources Folder into your Xcode project.
Usage
At first it makes sense to create an extensions on LogCategories to define your own categories.
import LoggingKit
extension LogCategories {
public var viewControllers: LogCategory { return .init("viewControllers") }
public var networking: LogCategory { return .init("networking") }
...
}
Then register your log providers in the application(application:didFinishLaunchingWithOptions:).
If you are using combine, LoggingKit offers some extensions on the Publisher type to log Self.Output and Self.Failure.
You can choose whichever category you want. The \.combine category is a custom defined one.
import LoggingKit
// logs `Self.Output`
myPublisher.logValue(logType: .info, logCategory: \.combine) {
"My Value is \($0)"
}
// logs `Self.Failure`
myPublisher.logError(logCategory: \.combine) {
"My Error is \($0)"
}
// logs `Self.Output` as well as `Self.Failure`
myPublisher.log()
Providers
The idea behind this small framework is, that you can extend it by writing your own log providers by conforming to the LogProvider protocol. These implementations then can be registered in the LogService.register(providers:) method.
LoggingKit comes with one pre-defined OSLogProvider . It uses os_log under the hood to log your messages. These messages can then be viewed in the Console.app application of your mac and on the console in Xcode.
Console App
Open Console.App on your mac, select the device from which you want to view the log messages, to view the messages printed by the OSLogProvider
Contributing
Contributions are very welcome 🙌
License
LoggingKit
Copyright (c) 2020 Alexander Weiß
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
LoggingKit
LoggingKit is a micro framework for logging based on log providers
Features
Combine
readyOSLogProvider
which usesos_log
under the hoodExample
The example application is the best way to see
LoggingKit
in action. Simply open theLoggingKit.xcodeproj
and run theExample
scheme.After the application has started you should see several log messages in your Xcode terminal and the
Console.app
for the device you ran the app on.Installation
Swift Package Manager
To integrate using Apple’s Swift Package Manager, add the following as a dependency to your
Package.swift
:Alternatively navigate to your Xcode project, select
Swift Packages
and click the+
icon to search forLoggingKit
.Manually
If you prefer not to use any of the aforementioned dependency managers, you can integrate LoggingKit into your project manually. Simply drag the
Sources
Folder into your Xcode project.Usage
At first it makes sense to create an extensions on
LogCategories
to define your own categories.Then register your log providers in the
application(application:didFinishLaunchingWithOptions:)
.After that Simply import
LoggingKit
in the files you want to use the logging methods and use them accordinglyCombine
If you are using combine,
LoggingKit
offers some extensions on thePublisher
type to logSelf.Output
andSelf.Failure
.You can choose whichever category you want. The
\.combine
category is a custom defined one.Providers
The idea behind this small framework is, that you can extend it by writing your own log providers by conforming to the
LogProvider
protocol. These implementations then can be registered in theLogService.register(providers:)
method.You can find an example
LogProvider
implementation in ./Example/MyTestLogProvider.swiftOSLogProvider
LoggingKit comes with one pre-defined
OSLogProvider
. It usesos_log
under the hood to log your messages. These messages can then be viewed in theConsole.app
application of your mac and on the console in Xcode.Console App
Open
Console.App
on your mac, select the device from which you want to view the log messages, to view the messages printed by theOSLogProvider
Contributing
Contributions are very welcome 🙌
License