Skip to content
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

Allow to specify an OAuth2Logger already during initialization #420

Open
berg-do opened this issue Apr 22, 2024 · 0 comments
Open

Allow to specify an OAuth2Logger already during initialization #420

berg-do opened this issue Apr 22, 2024 · 0 comments

Comments

@berg-do
Copy link

berg-do commented Apr 22, 2024

I am assigning a custom logger class to my oAuth2 instance (using the OAuth2CodeGrant).

Unfortunately in verbose mode the superclass (ultimately the OAuth2Requestable) will automatically create a OAuth2DebugLogger internally and log to it before there is the chance to apply a custom logger to the oAuth2 instance.

This results in a log like this:

[Debug] OAuth2: Initialization finished
[Debug] OAuth2: Looking for items in keychain
[Debug] OAuth2: Found access token, valid until 2024-04-22 09:50:02 +0000
[Debug] OAuth2: Found refresh token
[Debug] OAuth2: Found id token
2024-04-22 11:48:58.523 [INFO] Something, something, my own logging

Extending the OAuth2DebugLogger to implement my own logger logic does not seem to work. The extended apparently does not get called for some reason. I'm not entirely sure why, but it may be due to the OAuth2 dependency not calling stuff from classes that got extended outside the dependency itself.

The following sadly does not do the trick.

extension OAuth2DebugLogger {
    public func log(_ atLevel: OAuth2LogLevel, module: String?, filename: String?, line: Int?, function: String?, msg: @autoclosure () -> String) {
        MyLogger.log(level, atLevel, module, msg())
    }
}

My suggestion would be to allow specifying a logger instance during the OAuth2CodeGrant(settings: []) initializer that will already be used for verbose logging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants