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

Selectively disable type converter registration (was: Unexpected logging message) #451

Closed
pditommaso opened this issue Aug 24, 2018 · 13 comments

Comments

@pditommaso
Copy link
Contributor

Migrating an app to picocli (3.5.2) I'm getting the following unexpected logging message.

Aug 24, 2018 3:01:33 PM java.util.logging.LogManager$RootLogger log
SEVERE: Failed to resolve default logging config file: config/java.util.logging.properties

That's generated while instantiating the top CommandLine instance. Is there's any reason about that? It looks quite weird because at my knowledge picocli does not use any logging library.

@remkop
Copy link
Owner

remkop commented Aug 24, 2018

Hi, yes that is strange. As you said, picocli does not use any logging library, not even java.util.logging.

Is it possible picocli created an instance of your domain object, which (directly or indirectly) does logging in its constructor?

@pditommaso
Copy link
Contributor Author

It turns out it produced when executing this line

 BuiltIn.registerIfAvailable(converterRegistry, tracer, "java.sql.Connection", "java.sql.DriverManager","getConnection", String.class);

I think that triggers some drivers provided by other deps. I also find all that converters a bit overkill. Is there anyway to override the default registerBuiltInConverters mechanism? at a first look, I would say no.

@remkop
Copy link
Owner

remkop commented Aug 24, 2018

This is still very odd. All that the picocli code does is load the java.sql.Connection class and the java.sql.DriverManager class. No instances are created until needed. Out of interest, which JDBC driver or dependency produces the logging?

About making converter registration configurable: currently it isn't, but I would not object to adding some mechanism to selectively disable registration of some built-in converters. Perhaps via a system property; for example if -Dpicocli.skip.converters=java.sql.Connection,java.sql.Driver is specified, these two converters would not be registered.

@pditommaso
Copy link
Contributor Author

Out of interest, which JDBC driver or dependency produces the logging?

Not sure about that. I think it's the caused by the Apache Ignite deps in my project.

but I would not object to adding some mechanism to selectively disable registration

If so I would propose -Dpicocli.converters.includes=xx and -Dpicocli.converters.excludes=xx

@remkop
Copy link
Owner

remkop commented Aug 24, 2018

If so I would propose -Dpicocli.converters.includes=xx and -Dpicocli.converters.excludes=xx

What would -Dpicocli.converters.includes=xx do?

@pditommaso
Copy link
Contributor Author

pditommaso commented Aug 24, 2018

It would be applied only the classes specified

@remkop
Copy link
Owner

remkop commented Aug 24, 2018

I can see the need for selectively excluding some of the built-in type converters (for example to suppress this strange logging you are experiencing), but I don't see how it would be useful to have a system property that excludes all converters by default and only includes some specified ones. Can you explain the use case behind this?

@remkop
Copy link
Owner

remkop commented Aug 24, 2018

To clarify: I'm okay with the -Dpicocli.converters.excludes=x,x enhancement, and support for a -Dpicocli.converters.includes property can be added when a use case arises.

@pditommaso
Copy link
Contributor Author

Yes, I was suggesting to have a precise control on the converter classes include. Having a excludes clause does not prevent that new classes may be added implicitly added by a future version of picocli. Instead having an explicit includes would guarantees that wont' change over time.

I know it's a bit paranoid, but IMO adding not required converts, in particular via reflection, just add an unneeded overhead startup time and may cause unexpected side effects, as the one reported.

@remkop
Copy link
Owner

remkop commented Aug 24, 2018

The includes sounds a bit overkill to me but if you’re willing to provide a PR with unit tests I’m fine with your proposal.

It’s not obvious for users which converters are loaded via reflection and which aren’t. So, if we do this, these properties should probably be effective for all converters. Do you agree?

@remkop remkop changed the title Unexpected logging message Selectively disable type converter registration (was: Unexpected logging message) Aug 25, 2018
@pditommaso
Copy link
Contributor Author

Thinking twice, IMO it would make more sense to allow to specify the Interpreter as a constructor argument or a class attribute. Being so the user could override the registerBuiltInConverters method to provide their own converters.

@remkop
Copy link
Owner

remkop commented Aug 25, 2018

I’m not ready to make Interpreter public API...

@remkop remkop added this to the 3.6.1 milestone Sep 26, 2018
@remkop
Copy link
Owner

remkop commented Sep 27, 2018

This will be included in the upcoming 3.6.1 release.

@remkop remkop closed this as completed in 56dcfb8 Sep 27, 2018
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