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 set a default logger modifier #1427

Conversation

paul-dingemans
Copy link
Collaborator

@paul-dingemans paul-dingemans commented Mar 20, 2022

Description

  • The default loggerModifier can only be set once.
  • It is still possible to override the loggerModifier for a specific class by passing a loggerModifier to initKtLintKLogger.
  • When initKtLintKLogger is called without parameter, the defaultLoggerModifier is applied when set.

Checklist

  • PR description added
  • tests are added
  • CHANGELOG.md is updated

In case of adding a new rule:

  • README.md is updated
  • Rule has been applied on Ktlint itself and violations are fixed

Comment on lines +15 to +19
* Default modifier for the KLogger of new instances of classes calling [initKtLintKLogger]. Classes for which
* [initKtLintKLogger] has been called before setting this variable will not be changed. Also note, that this modifier
* can only be set once.
*/
public lateinit var defaultLoggerModifier: (KLogger) -> Unit
Copy link
Contributor

@z3d1k z3d1k Mar 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also note, that this modifier can only be set once.

Are there any checks to support that statement? lateinit only checks whether the variable has been initialized before it is accessed, no additional checks on its modification are performed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tnx again. That was a rookie mistake. I have improved it in #1430. I can not prevent the variable from being set more than once as it will break some integration tests in ktlint. I have now succeeded to print a warning (to discourage doing it) whenever it happens.

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