-
Notifications
You must be signed in to change notification settings - Fork 375
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a customisation point for injecting a logger in RxBluetoothKit #341
Add a customisation point for injecting a logger in RxBluetoothKit #341
Conversation
c65f1d8
to
33e5517
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @asaltvld30 for your pull requests. This is a great extension to the library and can be useful feature for some projects.
I've added some comments to your changes. Please update your pull request.
Can you also prepare some example how to use custom logger which I can add to the wiki page? |
Sure. For example, we can create a simple logger which counts the number of logs for each log level. private class SimpleCountLogger: Logger {
private var logCount: [UInt]
private var currentLogLevel: RxBluetoothKitLog.LogLevel = .verbose
init() {
logCount = [UInt](repeating: 0, count: Int(UInt8.max))
}
public func getLogCount() -> [UInt] {
return logCount
}
public func setLogLevel(_ logLevel: RxBluetoothKitLog.LogLevel) {
self.currentLogLevel = logLevel
}
public func getLogLevel() -> RxBluetoothKitLog.LogLevel {
return currentLogLevel
}
func log(
_ message: @autoclosure () -> String,
level: RxBluetoothKitLog.LogLevel,
file: StaticString,
function: StaticString,
line: UInt
) {
log(
message(),
level: level,
file: String(describing: file),
function: String(describing: function),
line: line
)
}
func log(
_ message: @autoclosure () -> String,
level: RxBluetoothKitLog.LogLevel,
file: String,
function: String,
line: UInt
) {
logCount[Int(level.rawValue)] += 1
}
} After this, one can simply inject it into the library by modifying RxBluetoothKitLogger.defaultLogger variable. A good place for injecting it can be the |
Adds the capability to route the RxBluetoothKit logs in another app by exposing a customisation point.
Each custom logger must conform to Logger protocol.
The current functionality remains unchanged unless another logger is injected.