Skip to content

Optimization log #18710

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

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ private void bindMetricsRegistryToHikariDataSource(HikariDataSource hikari) {
hikari.setMetricsTrackerFactory(new MicrometerMetricsTrackerFactory(this.registry));
}
catch (Exception ex) {
logger.warn("Failed to bind Hikari metrics: " + ex.getMessage());
if (logger.isWarnEnabled()) {
logger.warn("Failed to bind Hikari metrics: " + ex.getMessage());
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,10 @@ protected void doHealthCheck(Health.Builder builder) throws Exception {
builder.up();
}
else {
logger.warn(String.format("Free disk space below threshold. Available: %d bytes (threshold: %s)",
diskFreeInBytes, this.threshold));
if (logger.isWarnEnabled()) {
logger.warn(String.format("Free disk space below threshold. Available: %d bytes (threshold: %s)",
diskFreeInBytes, this.threshold));
}
builder.down();
}
builder.withDetail("total", this.path.getTotalSpace()).withDetail("free", diskFreeInBytes)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ static class Neo4jWebConfiguration {

@Bean
OpenSessionInViewInterceptor neo4jOpenSessionInViewInterceptor(Neo4jProperties properties) {
if (properties.getOpenInView() == null) {
if (properties.getOpenInView() == null && logger.isWarnEnabled()) {
logger.warn("spring.data.neo4j.open-in-view is enabled by default."
+ "Therefore, database queries may be performed during view "
+ "rendering. Explicitly configure "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public GroovyMarkupConfiguration(ApplicationContext applicationContext, GroovyTe
public void checkTemplateLocationExists() {
if (this.properties.isCheckTemplateLocation() && !isUsingGroovyAllJar()) {
TemplateLocation location = new TemplateLocation(this.properties.getResourceLoaderPath());
if (!location.exists(this.applicationContext)) {
if (!location.exists(this.applicationContext) && logger.isWarnEnabled()) {
logger.warn("Cannot find template location: " + location
+ " (please add some templates, check your Groovy "
+ "configuration, or set spring.groovy.template.check-template-location=false)");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,10 @@ static class JodaDateTimeJacksonConfiguration {

@Bean
SimpleModule jodaDateTimeSerializationModule(JacksonProperties jacksonProperties) {
logger.warn("Auto-configuration of Jackson's Joda-Time integration is deprecated in favor of using "
+ "java.time (JSR-310).");
if (logger.isWarnEnabled()) {
logger.warn("Auto-configuration of Jackson's Joda-Time integration is deprecated in favor of using "
+ "java.time (JSR-310).");
}
SimpleModule module = new SimpleModule();
JacksonJodaDateFormat jacksonJodaFormat = getJacksonJodaDateFormat(jacksonProperties);
if (jacksonJodaFormat != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ private void initialize(DataSourceInitializer initializer) {
}
}
catch (IllegalStateException ex) {
logger.warn("Could not send event to complete DataSource initialization (" + ex.getMessage() + ")");
if (logger.isWarnEnabled()) {
logger.warn("Could not send event to complete DataSource initialization (" + ex.getMessage() + ")");
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public MustacheAutoConfiguration(MustacheProperties mustache, ApplicationContext
public void checkTemplateLocationExists() {
if (this.mustache.isCheckTemplateLocation()) {
TemplateLocation location = new TemplateLocation(this.mustache.getPrefix());
if (!location.exists(this.applicationContext)) {
if (!location.exists(this.applicationContext) && logger.isWarnEnabled()) {
logger.warn("Cannot find template location: " + location
+ " (please add some templates, check your Mustache configuration, or set spring.mustache."
+ "check-template-location=false)");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ protected JpaWebConfiguration(JpaProperties jpaProperties) {

@Bean
public OpenEntityManagerInViewInterceptor openEntityManagerInViewInterceptor() {
if (this.jpaProperties.getOpenInView() == null) {
if (this.jpaProperties.getOpenInView() == null && logger.isWarnEnabled()) {
logger.warn("spring.jpa.open-in-view is enabled by default. "
+ "Therefore, database queries may be performed during view "
+ "rendering. Explicitly configure spring.jpa.open-in-view to disable this warning");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ protected void logError(ServerRequest request, ServerResponse response, Throwabl
logger.debug(request.exchange().getLogPrefix() + formatError(throwable, request));
}
if (HttpStatus.resolve(response.rawStatusCode()) != null
&& response.statusCode().equals(HttpStatus.INTERNAL_SERVER_ERROR)) {
&& response.statusCode().equals(HttpStatus.INTERNAL_SERVER_ERROR) && logger.isErrorEnabled()) {
logger.error(request.exchange().getLogPrefix() + "500 Server Error for " + formatRequest(request),
throwable);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ void startServer() throws Exception {
if (!this.server.isStarted()) {
this.server.start();
}
logger.info("LiveReload server is running on port " + this.server.getPort());
if (logger.isInfoEnabled()) {
logger.info("LiveReload server is running on port " + this.server.getPort());
}
}
catch (Exception ex) {
logger.warn("Unable to start LiveReload server");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ UrlHandlerMapper remoteRestartHandlerMapper(HttpRestartServer server, ServerProp
RemoteDevToolsProperties remote = properties.getRemote();
String servletContextPath = (servlet.getContextPath() != null) ? servlet.getContextPath() : "";
String url = servletContextPath + remote.getContextPath() + "/restart";
logger.warn("Listening for remote restart updates on " + url);
if (logger.isWarnEnabled()) {
logger.warn("Listening for remote restart updates on " + url);
}
Handler handler = new HttpRestartServerHandler(server);
return new UrlHandlerMapper(url, handler);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,12 @@ private void addUrl(URL url) {
this.folders.add(ResourceUtils.getFile(url));
}
catch (Exception ex) {
logger.warn("Unable to get classpath URL " + url);
logger.trace("Unable to get classpath URL " + url, ex);
if (logger.isWarnEnabled()) {
logger.warn("Unable to get classpath URL " + url);
}
if (logger.isTraceEnabled()) {
logger.trace("Unable to get classpath URL " + url, ex);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,12 @@ public class DevToolsPropertyDefaultsPostProcessor implements EnvironmentPostPro
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
if (DevToolsEnablementDeducer.shouldEnable(Thread.currentThread()) && isLocalApplication(environment)) {
if (canAddProperties(environment)) {
logger.info("Devtools property defaults active! Set '" + ENABLED + "' to 'false' to disable");
if (logger.isInfoEnabled()) {
logger.info("Devtools property defaults active! Set '" + ENABLED + "' to 'false' to disable");
}
environment.getPropertySources().addLast(new MapPropertySource("devtools", PROPERTIES));
}
if (isWebApplication(environment) && !environment.containsProperty(WEB_LOGGING)) {
if (isWebApplication(environment) && !environment.containsProperty(WEB_LOGGING) && logger.isInfoEnabled()) {
logger.info("For additional web related logging consider setting the '" + WEB_LOGGING
+ "' property to 'DEBUG'");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,10 @@ private void performUpload(ClassLoaderFiles classLoaderFiles, byte[] bytes) thro
return;
}
catch (SocketException ex) {
logger.warn("A failure occurred when uploading to " + this.uri
+ ". Upload will be retried in 2 seconds");
if (logger.isWarnEnabled()) {
logger.warn("A failure occurred when uploading to " + this.uri
+ ". Upload will be retried in 2 seconds");
}
logger.debug("Upload failure", ex);
Thread.sleep(2000);
}
Expand All @@ -128,8 +130,10 @@ private void performUpload(ClassLoaderFiles classLoaderFiles, byte[] bytes) thro
}

private void logUpload(ClassLoaderFiles classLoaderFiles) {
int size = classLoaderFiles.size();
logger.info("Uploaded " + size + " class " + ((size != 1) ? "resources" : "resource"));
if (logger.isInfoEnabled()) {
int size = classLoaderFiles.size();
logger.info("Uploaded " + size + " class " + ((size != 1) ? "resources" : "resource"));
}
}

private byte[] serialize(ClassLoaderFiles classLoaderFiles) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ private void logWarnings() {
if (!remoteProperties.getRestart().isEnabled()) {
logger.warn("Remote restart is disabled.");
}
if (!this.remoteUrl.startsWith("https://")) {
if (!this.remoteUrl.startsWith("https://") && logger.isWarnEnabled()) {
logger.warn("The connection to " + this.remoteUrl
+ " is insecure. You should use a URL starting with 'https://'.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ private static List<URL> getUrlsFromManifestClassPathAttribute(URL jarUrl, JarFi
throw new IllegalStateException("Class-Path attribute contains malformed URL", ex);
}
}
if (!nonExistentEntries.isEmpty()) {
if (!nonExistentEntries.isEmpty() && logger.isInfoEnabled()) {
logger.info("The Class-Path manifest attribute in " + jarFile.getName()
+ " referenced one or more files that do not exist: "
+ StringUtils.collectionToCommaDelimitedString(nonExistentEntries));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ private void onApplicationStartingEvent(ApplicationStartingEvent event) {
Restarter.initialize(args, false, initializer, restartOnInitialize);
}
else {
logger.info("Restart disabled due to System property '" + ENABLED_PROPERTY + "' being set to false");
if (logger.isInfoEnabled()) {
logger.info("Restart disabled due to System property '" + ENABLED_PROPERTY + "' being set to false");
}
Restarter.disable();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ protected HttpTunnelConnection(String url, ClientHttpRequestFactory requestFacto

@Override
public TunnelChannel open(WritableByteChannel incomingChannel, Closeable closeable) throws Exception {
logger.trace("Opening HTTP tunnel to " + this.uri);
if (logger.isTraceEnabled()) {
logger.trace("Opening HTTP tunnel to " + this.uri);
}
return new TunnelChannel(incomingChannel, closeable);
}

Expand Down Expand Up @@ -152,7 +154,10 @@ public void run() {
}
catch (IOException ex) {
if (ex instanceof ConnectException) {
logger.warn("Failed to connect to remote application at " + HttpTunnelConnection.this.uri);
if (logger.isWarnEnabled()) {
logger.warn(
"Failed to connect to remote application at " + HttpTunnelConnection.this.uri);
}
}
else {
logger.trace("Unexpected connection error", ex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ public int start() throws IOException {
ServerSocketChannel serverSocketChannel = ServerSocketChannel.open();
serverSocketChannel.socket().bind(new InetSocketAddress(this.listenPort));
int port = serverSocketChannel.socket().getLocalPort();
logger.trace("Listening for TCP traffic to tunnel on port " + port);
if (logger.isTraceEnabled()) {
logger.trace("Listening for TCP traffic to tunnel on port " + port);
}
this.serverThread = new ServerThread(serverSocketChannel);
this.serverThread.start();
return port;
Expand Down Expand Up @@ -144,7 +146,9 @@ public ServerThread(ServerSocketChannel serverSocketChannel) {
}

public void close() throws IOException {
logger.trace("Closing tunnel client on port " + this.serverSocketChannel.socket().getLocalPort());
if (logger.isTraceEnabled()) {
logger.trace("Closing tunnel client on port " + this.serverSocketChannel.socket().getLocalPort());
}
this.serverSocketChannel.close();
this.acceptConnections = false;
interrupt();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ public SocketTargetServerConnection(PortProvider portProvider) {
@Override
public ByteChannel open(int socketTimeout) throws IOException {
SocketAddress address = new InetSocketAddress(this.portProvider.getPort());
logger.trace("Opening tunnel connection to target server on " + address);
if (logger.isTraceEnabled()) {
logger.trace("Opening tunnel connection to target server on " + address);
}
SocketChannel channel = SocketChannel.open(address);
channel.socket().setSoTimeout(socketTimeout);
return new TimeoutAwareChannel(channel);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,10 @@ public void printBanner(Environment environment, Class<?> sourceClass, PrintStre
printBanner(environment, out);
}
catch (Throwable ex) {
logger.warn("Image banner not printable: " + this.image + " (" + ex.getClass() + ": '" + ex.getMessage()
+ "')");
if (logger.isWarnEnabled()) {
logger.warn("Image banner not printable: " + this.image + " (" + ex.getClass() + ": '" + ex.getMessage()
+ "')");
}
logger.debug("Image banner printing failure", ex);
}
finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,10 @@ public void printBanner(Environment environment, Class<?> sourceClass, PrintStre
out.println(banner);
}
catch (Exception ex) {
logger.warn(
"Banner not printable: " + this.resource + " (" + ex.getClass() + ": '" + ex.getMessage() + "')",
ex);
if (logger.isWarnEnabled()) {
logger.warn("Banner not printable: " + this.resource + " (" + ex.getClass() + ": '" + ex.getMessage()
+ "')", ex);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ private void appendOn(StringBuilder message) {
if (System.getProperty("os.name").toLowerCase().contains("mac")) {
warning.append(" (macOS machines may need to add entries to /etc/hosts)");
}
logger.warn(warning.append("."));
if (logger.isWarnEnabled()) {
logger.warn(warning.append("."));
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,14 @@ public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
String encoding = System.getProperty("file.encoding");
String desired = environment.getProperty("spring.mandatory-file-encoding");
if (encoding != null && !desired.equalsIgnoreCase(encoding)) {
logger.error("System property 'file.encoding' is currently '" + encoding + "'. It should be '" + desired
+ "' (as defined in 'spring.mandatoryFileEncoding').");
logger.error("Environment variable LANG is '" + System.getenv("LANG")
+ "'. You could use a locale setting that matches encoding='" + desired + "'.");
logger.error("Environment variable LC_ALL is '" + System.getenv("LC_ALL")
+ "'. You could use a locale setting that matches encoding='" + desired + "'.");
if (logger.isErrorEnabled()) {
logger.error("System property 'file.encoding' is currently '" + encoding + "'. It should be '" + desired
+ "' (as defined in 'spring.mandatoryFileEncoding').");
logger.error("Environment variable LANG is '" + System.getenv("LANG")
+ "'. You could use a locale setting that matches encoding='" + desired + "'.");
logger.error("Environment variable LC_ALL is '" + System.getenv("LC_ALL")
+ "'. You could use a locale setting that matches encoding='" + desired + "'.");
}
throw new IllegalStateException("The Java Virtual Machine has not been configured to use the "
+ "desired default character encoding (" + desired + ").");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,9 @@ private BiConsumer<String, LogLevel> getLogLevelConfigurer(LoggingSystem system)
system.setLogLevel(name, level);
}
catch (RuntimeException ex) {
this.logger.error("Cannot set level '" + level + "' for '" + name + "'");
if (this.logger.isErrorEnabled()) {
this.logger.error("Cannot set level '" + level + "' for '" + name + "'");
}
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ private List<FailureAnalyzer> loadFailureAnalyzers(ClassLoader classLoader) {
analyzers.add((FailureAnalyzer) constructor.newInstance());
}
catch (Throwable ex) {
logger.trace("Failed to load " + analyzerName, ex);
if (logger.isTraceEnabled()) {
logger.trace("Failed to load " + analyzerName, ex);
}
}
}
AnnotationAwareOrderComparator.sort(analyzers);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ public void onApplicationEvent(WebServerInitializedEvent event) {
portFile.deleteOnExit();
}
catch (Exception ex) {
logger.warn(String.format("Cannot create port file %s", this.file));
if (logger.isWarnEnabled()) {
logger.warn(String.format("Cannot create port file %s", this.file));
}
}
}

Expand Down