Skip to content

Commit 13ca1f6

Browse files
committed
Merge branch 'develop'
2 parents 1f71349 + 64bff3f commit 13ca1f6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+9757
-345
lines changed

.github/workflows/main.yml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
name: CI
22

3-
on:
4-
push:
5-
branches:
6-
- master
7-
- develop
8-
- /^hotfix.*$/
9-
- /^feature.*$/
3+
on: [push]
104

115
jobs:
126
tests:
@@ -22,4 +16,4 @@ jobs:
2216
steps:
2317
- uses: actions/checkout@v1
2418
- name: fastlane ios compatibilityTests
25-
run: fastlane ios compatibilityTests
19+
run: fastlane ios compatibilityTests

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Icon
2929
._*
3030

3131
# Documentation
32-
Documentation
32+
#Documentation
3333

3434
# Files that might appear in the root of a volume
3535
.DocumentRevisions-V100
@@ -107,3 +107,4 @@ fastlane/test_output
107107
.bundle/**
108108
.vendor/**
109109
.swiftpm/**
110+
.vendor/**

.jazzy.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ copyright: Copyright 2020 Alexander Weiß
44
author: Alexander Weiß
55
xcodebuild_arguments: [-target, LoggingKit-iOS]
66
clean: true
7-
output: ./Documentation
7+
output: ./docs

Configs/LoggingKit.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<key>CFBundlePackageType</key>
1818
<string>FMWK</string>
1919
<key>CFBundleShortVersionString</key>
20-
<string>1.0.0</string>
20+
<string>2.0.0</string>
2121
<key>CFBundleSignature</key>
2222
<string>????</string>
2323
<key>CFBundleVersion</key>

Configs/LoggingKitTests.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<key>CFBundlePackageType</key>
1616
<string>BNDL</string>
1717
<key>CFBundleShortVersionString</key>
18-
<string>1.0.0</string>
18+
<string>2.0.0</string>
1919
<key>CFBundleSignature</key>
2020
<string>????</string>
2121
<key>CFBundleVersion</key>

Example/AppDelegate.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//
88

99
import UIKit
10+
import LoggingKit
1011

1112
// MARK: - AppDelegate
1213

@@ -30,12 +31,18 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
3031
/// - Returns: The launch result
3132
func application(_ application: UIApplication,
3233
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
34+
35+
36+
LogService.register(logProviders: MyTestLogProvider())
37+
38+
3339
// Initialize UIWindow
3440
self.window = .init(frame: UIScreen.main.bounds)
3541
// Set RootViewController
3642
self.window?.rootViewController = self.rootViewController
3743
// Make Key and Visible
3844
self.window?.makeKeyAndVisible()
45+
3946
// Return positive launch
4047
return true
4148
}

Example/MyTestLogProvider.swift

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//
2+
// MyTestLogProvider.swift
3+
// Example
4+
//
5+
// Created by Alexander Weiß on 13.06.20.
6+
// Copyright © 2020 Alexander Weiß. All rights reserved.
7+
//
8+
9+
import Foundation
10+
import LoggingKit
11+
12+
class MyTestLogProvider: LogProvider {
13+
14+
static var dateFormatter: DateFormatter = {
15+
let df = DateFormatter()
16+
df.dateFormat = "yyyy-MM-dd HH:mm:ssSSS"
17+
df.locale = Locale.current
18+
df.timeZone = TimeZone.current
19+
return df
20+
}()
21+
22+
23+
func log(_ event: LogType, _ message: @autoclosure () -> Any?, logCategory: KeyPath<LogCategories, LogCategory>, fileName: StaticString, functionName: StaticString, lineNumber: Int) {
24+
25+
guard let message = message() else {
26+
return
27+
}
28+
29+
let category = LoggingCategories[logCategory]
30+
let timeString = MyTestLogProvider.dateFormatter.string(from: Date())
31+
let fileString = "[\((String(describing: fileName) as NSString).lastPathComponent):\(lineNumber)] \(functionName)"
32+
33+
print("\(timeString) [\(event.rawValue)] - [\(category._key)] - \(fileString) > \(message)")
34+
35+
}
36+
}

Example/Resources/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<key>CFBundlePackageType</key>
1818
<string>APPL</string>
1919
<key>CFBundleShortVersionString</key>
20-
<string>1.0.0</string>
20+
<string>2.0.0</string>
2121
<key>CFBundleVersion</key>
2222
<string>1</string>
2323
<key>LSRequiresIPhoneOS</key>

Example/ViewController.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,12 @@ class ViewController: UIViewController {
4343
self.view.backgroundColor = .white
4444

4545
// Traditional methods
46-
logger.debug("Hello Debug", logCategory: \.viewControllers)
47-
logger.info("Hello Info", logCategory: \.viewControllers)
48-
logger.fault("Hello Fault", logCategory: \.viewControllers)
49-
logger.error("Hello Error", logCategory: \.viewControllers)
46+
LogService.shared.debug("Hello Debug", logCategory: \.viewControllers)
47+
LogService.shared.verbose("Hello Verbose", logCategory: \.viewControllers)
48+
LogService.shared.info("Hello Info", logCategory: \.viewControllers)
49+
LogService.shared.warning("Hello Warning", logCategory: \.viewControllers)
50+
LogService.shared.error("Hello Error", logCategory: \.viewControllers)
51+
5052

5153
// Combine publishers
5254
sub = Result<Int, NumberError>.Publisher(5)

LoggingKit.xcodeproj/project.pbxproj

Lines changed: 95 additions & 33 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 50 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,19 @@
1616
</a>
1717
</p>
1818

19-
20-
2119
<p align="center">
22-
LoggingKit is a micro framework for logging in which uses `os_log` under the hood.
20+
LoggingKit is a micro framework for logging based on log providers
2321
</p>
2422

2523
## Features
2624

27-
- [x] Uses `os_log` under the hood
25+
- [x] Define your own log providers
2826
- [x] `Combine` ready
27+
- [x] Comes with pre-defined `OSLogProvider` which uses `os_log` under the hood
2928

3029
## Example
3130

32-
The example application is the best way to see `LoggingKit` in action. Simply open the `LoggingKit.xcodeproj` and run the `Example` scheme.
31+
The example application is the best way to see `LoggingKit` in action. Simply open the `LoggingKit.xcodeproj` and run the `Example` scheme.
3332

3433
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.
3534

@@ -41,11 +40,11 @@ After the application has started you should see several log messages in your Xc
4140

4241
To integrate LoggingKit into your Xcode project using Carthage, specify it in your `Cartfile`:
4342

44-
```ogdl
43+
```
4544
github "alexanderwe/LoggingKit"
4645
```
4746

48-
Run `carthage update` to build the framework and drag the built `LoggingKit.framework` into your Xcode project.
47+
Run `carthage update` to build the framework and drag the built `LoggingKit.framework` into your Xcode project.
4948

5049
On your application targets’ “Build Phases” settings tab, click the “+” icon and choose “New Run Script Phase” and add the Framework path as mentioned in [Carthage Getting started Step 4, 5 and 6](https://github.com/Carthage/Carthage/blob/master/README.md#if-youre-building-for-ios-tvos-or-watchos)
5150

@@ -55,7 +54,7 @@ To integrate using Apple's [Swift Package Manager](https://swift.org/package-man
5554

5655
```swift
5756
dependencies: [
58-
.package(url: "https://github.com/alexanderwe/LoggingKit.git", from: "1.0.0")
57+
.package(url: "https://github.com/alexanderwe/LoggingKit.git", from: "2.0.0")
5958
]
6059
```
6160

@@ -67,8 +66,7 @@ If you prefer not to use any of the aforementioned dependency managers, you can
6766

6867
## Usage
6968

70-
71-
At first it makes sense to create an extensions on `LogCategories` to define your own categories.
69+
At first it makes sense to create an extensions on `LogCategories` to define your own categories.
7270

7371
```swift
7472
import LoggingKit
@@ -80,24 +78,46 @@ extension LogCategories {
8078
}
8179
```
8280

83-
After that Simply import `LoggingKit` in the files you want to use the logging methods and use them accordingly
81+
Then register your log providers in the `application(application:didFinishLaunchingWithOptions:)`.
8482

8583
```swift
86-
import LoggingKit
84+
import LoggingKit
85+
86+
class AppDelegate: UIResponder, UIApplicationDelegate {
8787

88-
logger.debug("Hello Debug", logCategory: \.viewControllers)
89-
logger.info("Hello Info", logCategory: \.viewControllers)
90-
logger.fault("Hello Fault", logCategory: \.viewControllers)
91-
logger.error("Hello Error", logCategory: \.viewControllers)
88+
...
9289

90+
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions:[UIApplication.LaunchOptionsKey: Any]?) -> Bool {
91+
92+
LogService.register(logProviders: LogProvider, LogProvider ...)
93+
94+
}
95+
96+
...
97+
}
9398
```
9499

95-
### Combine
100+
After that Simply import `LoggingKit` in the files you want to use the logging methods and use them accordingly
96101

97-
If you are using combine `LoggingKit` offers some extensions on the `Publisher` type to log `Self.Output` and `Self.Failure`.
102+
```swift
103+
import LoggingKit
104+
105+
LogService.shared.debug("Hello Debug", logCategory: \.viewControllers)
106+
LogService.shared.verbose("Hello Verbose", logCategory: \.viewControllers)
107+
LogService.shared.info("Hello Info", logCategory: \.viewControllers)
108+
LogService.shared.warning("Hello Warning", logCategory: \.viewControllers)
109+
LogService.shared.error("Hello Error", logCategory: \.viewControllers)
110+
111+
```
112+
113+
### Combine
114+
115+
If you are using combine, `LoggingKit` offers some extensions on the `Publisher` type to log `Self.Output` and `Self.Failure`.
116+
117+
You can choose whichever category you want. The `\.combine` category is a custom defined one.
98118

99119
```swift
100-
import LoggingKit
120+
import LoggingKit
101121

102122
// logs `Self.Output`
103123
myPublisher.logValue(logType: .info, logCategory: \.combine) {
@@ -113,15 +133,24 @@ myPublisher.logError(logCategory: \.combine) {
113133
myPublisher.log()
114134
```
115135

136+
### Providers
137+
138+
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.
116139

117-
### Console App
140+
You can find an example `LogProvider` implementation in [./Example/MyTestLogProvider.swift](./Example/MyTestLogProvider.swift)
118141

119-
Now can open `Console.App` on your mac, select the device from which you want to view the log messages.
142+
#### OSLogProvider
120143

144+
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.
145+
146+
##### Console App
147+
148+
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`
121149

122150
![Console App Screenshot](./assets/console_screenshot.png)
123151

124152
## Contributing
153+
125154
Contributions are very welcome 🙌
126155

127156
## License

Sources/Combine+LoggingKit.swift renamed to Sources/Combine/Combine+LoggingKit.swift

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,16 @@ extension Publisher {
3232

3333
return self
3434
.mapError {
35-
logger.doLog(message($0),
36-
logType: .error,
37-
logCategory: logCategory,
38-
functionName: functionName,
39-
fileName: fileName,
40-
lineNumber: lineNumber
35+
LogService.shared.error(
36+
message($0),
37+
logCategory: logCategory,
38+
fileName: fileName,
39+
functionName: functionName,
40+
lineNumber: lineNumber
4141
)
4242
return $0
43-
}
44-
.eraseToAnyPublisher()
43+
}
44+
.eraseToAnyPublisher()
4545
}
4646

4747
/// Publisher which logs the ouput value of the preceding publisher
@@ -54,7 +54,7 @@ extension Publisher {
5454
/// - lineNumber: Line number in which the message is logged
5555
/// - message: Message to log
5656
/// - Returns: Returns an AnyPublisher with `AnyPublisher<Self.Output, Self.Failure>`
57-
public func logValue(logType: OSLogType = .default,
57+
public func logValue(logType: LogType = .verbose,
5858
logCategory: KeyPath<LogCategories, LogCategory> = \.default,
5959
functionName: StaticString = #function,
6060
fileName: StaticString = #file,
@@ -64,16 +64,16 @@ extension Publisher {
6464

6565
return self
6666
.map {
67-
logger.doLog(message($0),
68-
logType: logType,
69-
logCategory: logCategory,
70-
functionName: functionName,
71-
fileName: fileName,
72-
lineNumber: lineNumber
67+
LogService.shared.log(logType,
68+
message($0),
69+
logCategory: logCategory,
70+
fileName: fileName,
71+
functionName: functionName,
72+
lineNumber: lineNumber
7373
)
7474
return $0
75-
}
76-
.eraseToAnyPublisher()
75+
}
76+
.eraseToAnyPublisher()
7777
}
7878

7979
/// Publisher which both logs the Self.Failure value and the Self.Output value of the preceding publisher
@@ -89,7 +89,7 @@ extension Publisher {
8989
public func log(
9090
messageValue: @escaping (Self.Output) -> Any? = { (output: Self.Output) in return output },
9191
messageError: @escaping (Self.Failure) -> Any? = { (output: Self.Failure) in return output },
92-
valuelogType: OSLogType = .default,
92+
valuelogType: LogType = .verbose,
9393
logCategory: KeyPath<LogCategories, LogCategory> = \.default,
9494
functionName: StaticString = #function,
9595
fileName: StaticString = #file,
@@ -103,13 +103,13 @@ extension Publisher {
103103
fileName: fileName,
104104
lineNumber: lineNumber,
105105
messageValue
106-
)
106+
)
107107
.logError(logCategory: logCategory,
108108
functionName: functionName,
109109
fileName: fileName,
110110
lineNumber: lineNumber,
111111
messageError
112-
)
112+
)
113113
.eraseToAnyPublisher()
114114
}
115115
}

Sources/LogCategory.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public var LoggingCategories = LogCategories()
1919
/// Container for holding different log categories
2020
public struct LogCategories {
2121

22-
subscript(keyPath: KeyPath<LogCategories, LogCategory>) -> LogCategory {
22+
public subscript(keyPath: KeyPath<LogCategories, LogCategory>) -> LogCategory {
2323
return self[keyPath: keyPath]
2424
}
2525
}
@@ -38,7 +38,7 @@ public struct LogCategory {
3838
//swiftlint:enable identifier_name
3939

4040
var logger: OSLog {
41-
return OSLog(subsystem: Bundle.main.bundleIdentifier ?? "dev.teabye.loggingkit", category: _key)
41+
return OSLog(subsystem: Bundle.main.bundleIdentifier ?? "dev.teabyte.loggingkit", category: _key)
4242
}
4343

4444
public init(_ key: String) {

0 commit comments

Comments
 (0)