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

Enhance ConfigLoggingBundle to log a minimized Dropwizard configuration (with constructor default values excluded). #2011

Merged
merged 1 commit into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion liftwizard-logging/liftwizard-bundle-logging-config/pom.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2020 Craig Motlin
~ Copyright 2024 Craig Motlin
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -62,6 +62,11 @@
<artifactId>jackson-core</artifactId>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,14 @@ private static void logConfiguration(
@Nonnull ObjectMapper objectMapper)
throws JsonProcessingException
{
String configurationString = objectMapper.writeValueAsString(configuration);
LOGGER.info("Inferred Dropwizard configuration:\n{}", configurationString);
ObjectMapper nonDefaultObjectMapper = objectMapper.copy();
nonDefaultObjectMapper.setMixInResolver(new JsonIncludeNonDefaultMixInResolver());

String configurationString = nonDefaultObjectMapper.writeValueAsString(configuration);
LOGGER.info("Dropwizard configuration (minimized):\n{}", configurationString);

String fullConfigurationString = objectMapper.writeValueAsString(configuration);
LOGGER.debug("Dropwizard configuration (full):\n{}", fullConfigurationString);

Optional<Object> maybeDefaultConfiguration = ConfigLoggingBundle
.getConstructor(configuration)
Expand All @@ -89,7 +95,7 @@ private static void logConfiguration(
if (LOGGER.isDebugEnabled())
{
String defaultConfigurationString = objectMapper.writeValueAsString(defaultConfiguration);
LOGGER.debug("Default Dropwizard configuration:\n{}", defaultConfigurationString);
LOGGER.debug("Dropwizard configuration default values:\n{}", defaultConfigurationString);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright 2024 Craig Motlin
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.liftwizard.dropwizard.bundle.config.logging;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;

@JsonInclude(Include.NON_DEFAULT)
public class JsonIncludeNonDefaultMixIn
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright 2024 Craig Motlin
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.liftwizard.dropwizard.bundle.config.logging;

import com.fasterxml.jackson.databind.introspect.ClassIntrospector.MixInResolver;

public class JsonIncludeNonDefaultMixInResolver
implements MixInResolver
{
@Override
public Class<?> findMixInClassFor(Class<?> cls)
{
return JsonIncludeNonDefaultMixIn.class;
}

@Override
public MixInResolver copy()
{
return this;
}
}