Sitelet https://github.com/OAuthSwift/OAuthSwift/pull/665
Skip to content

Added custom log action - #665

Open
Vortec4800 wants to merge 1 commit into
OAuthSwift:masterfrom
Vortec4800:custom-logger
Open

Vortec4800 wants to merge 1 commit into
OAuthSwift:masterfrom
Vortec4800:custom-logger

Conversation

@Vortec4800

Copy link
Copy Markdown

The new logging mechanism looks really useful, however, I wanted to extend it to integrate with my app's existing logging system. I added a custom log action that accepts a closure, and the log action is used instead of just printing to the console so the actual log can be customized.

This extends the work done by @svoip and the logging system.

In order to use this new functionality, you would add something like this:

OAuthSwift.setLogLevel(.trace)
OAuthSwift.setCustomLogAction { message in
   CustomLogger("[OAUTHSWIFT] \(message)")
}

@phimage

phimage commented Jun 11, 2021

Copy link
Copy Markdown
Member

Hi,
I think it’s useless. OAuthLogProtocol is a protocol. Make your class or structure that implement it and put an instance in OAuthSwift.log

@Vortec4800

Copy link
Copy Markdown
Author

That's the path I started to go down before I did this. Unfortunately, it doesn't work for 2 reasons.

The first one, OAuthSwift.log isn't a public property, so you would need a PR on OAuthSwift to add a func to set a custom logging subclass anyway.

The second issue is the default implementations are in an extension on the protocol. If you create a subclass and set it as the logging class, Swift still calls the implementations in the extension and not those in the subclass. It might be possible to reorganize everything to make it work, but the few things I tried caused errors due to the default parameters to get file and line information.

This seemed like the best way to get custom logging functionality without totally re-writing the logger which didn't seem necessary.

@Vortec4800

Copy link
Copy Markdown
Author

Hi, any more info on this PR? I still think it's useful functionality to be able to customize logging, but the proposed solution of using the protocol isn't possible.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants