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

spring-boot-1612: make console and file output configurable #1720

Closed

Conversation

liujiong1982
Copy link
Contributor

1 disable the file output unless LOG_FILE is set
2 make the console optional

fixes: gh-1612

@wilkinsona
Copy link
Member

This PR doesn't implement the changes described in #1612. With the changes in place the console is off by default. The intention was to have the console enabled and the file appender disabled by default. Furthermore, you've also introduced conditional logic to the Logback configuration, but haven't added a dependency on Janino (which is required for the conditional logic to work). If I add Janino to the classpath, setting logging.console to true doesn't enable the console.

@wilkinsona wilkinsona added the status: waiting-for-feedback We need additional information before we can continue label Oct 16, 2014
@liujiong1982
Copy link
Contributor Author

make console output default true and add Janino to spring-boot

@dsyer
Copy link
Member

dsyer commented Oct 19, 2014

Thanks for the code. However I'm not sure I like this change. I don't like having to pay for an extra dependency on this. I also kind of thought we could make it work for all logging systems (eg by using a different config file if LOG_FILE is set).

@liujiong1982
Copy link
Contributor Author

@dsyer
I have a solution which won't require extra dependency.
Current it supports java, logback and log4j, what do you mean by all logging system?

@dsyer
Copy link
Member

dsyer commented Oct 20, 2014

The current pull request has a janino dependency, so where is the new solution?

By "system" I meant LoggingSysten (so logback, log4j etc.).

@liujiong1982
Copy link
Contributor Author

janino dependency is removed now.
This PR supports logging, logback and log4j.

Assert.notNull(configLocation, "ConfigLocation must not be null");
String resolvedLocation = SystemPropertyUtils.resolvePlaceholders(configLocation);
try {
LogManager.getLogManager().readConfiguration(
ResourceUtils.getURL(resolvedLocation).openStream());
if (fileOutput) {
Copy link
Member

Choose a reason for hiding this comment

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

Do we really need to use the Java API for the loggers here? I was hoping this would be in a config file. What happens if the user sets additional logger levels later, do they inherit from their parent or something? If so why do we need to iterate here (can't you just set the handler for the root logger).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

make java logging configured to root logger now

Copy link
Member

Choose a reason for hiding this comment

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

I still don't like doing this in Java. It makes the log config files dependent on a very specific code path in the framework. It would be nice for users to be able to copy paste those files and use them as is.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It would be nice for users to be able to copy paste those files and use them as is.
you mean the config files?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

do you have any idea how a properties file can reference variable defined in the same properties file?
like CONSOLE_LOG_LEVEL=OFF
java.util.logging.ConsoleHandler.level = ${CONSOLE_LOG_LEVEL}

@liujiong1982
Copy link
Contributor Author

remove comment and make java logging to root logger

LoggerContext context = (LoggerContext) factory;
context.stop();
context.reset();
try {
URL url = ResourceUtils.getURL(resolvedLocation);
new ContextInitializer(context).configureByResource(url);
if (consoleOutput) {
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we could do the content of these two if() statements in separate <import/> files in logack.xml (instead of using the Java API, nice as it is)?

@liujiong1982
Copy link
Contributor Author

Get one of the four config files according to user properties files for fileoutput and consoleoutput

@dsyer
Copy link
Member

dsyer commented Oct 27, 2014

I tried to merge this and got a conflict. I think it might be easier for you to rebase onto master and re-submit. Sorry this is taking so long.

@dsyer dsyer removed the status: waiting-for-feedback We need additional information before we can continue label Oct 28, 2014
humaolin pushed a commit to humaolin/spring-boot that referenced this pull request May 7, 2022
MockRestRequestMatchers was using org.junit.Assert.assertNotNull
and thus could not be used in projects that use e.g. TestNG instead
of JUnit 4.
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.

Add first class support for disabling logback ConsoleAppender
3 participants