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

Added custom log action #665

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Vortec4800
Copy link

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
Copy link
Member

phimage commented Jun 11, 2021

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

None yet

2 participants