Skip to content

Commit

Permalink
Add debug logging (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
big-andy-coates authored Oct 26, 2022
1 parent d58ae13 commit 92d0efc
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ subprojects {
extra.apply {
set("creekBaseVersion", "0.2.0-SNAPSHOT")
set("creekTestVersion", "0.2.0-SNAPSHOT")
set("creekObsVersion", "0.2.0-SNAPSHOT")
set("spotBugsVersion", "4.6.0") // https://mvnrepository.com/artifact/com.github.spotbugs/spotbugs-annotations

set("log4jVersion", "2.19.0") // https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-core
Expand Down
2 changes: 2 additions & 0 deletions resource/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ plugins {
}

val creekBaseVersion : String by extra
val creekObsVersion : String by extra

dependencies {
api(project(":metadata"))
implementation("org.creekservice:creek-base-type:$creekBaseVersion")
implementation("org.creekservice:creek-observability-logging:$creekObsVersion")
}
1 change: 1 addition & 0 deletions resource/src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module creek.platform.resource {
requires transitive creek.platform.metadata;
requires creek.base.type;
requires creek.observability.logging;

exports org.creekservice.api.platform.resource;
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
import java.util.stream.Stream;
import org.creekservice.api.base.annotation.VisibleForTesting;
import org.creekservice.api.base.type.CodeLocation;
import org.creekservice.api.observability.logging.structured.StructuredLogger;
import org.creekservice.api.observability.logging.structured.StructuredLoggerFactory;
import org.creekservice.api.platform.metadata.ComponentDescriptor;
import org.creekservice.api.platform.metadata.ResourceDescriptor;
import org.creekservice.api.platform.metadata.ResourceHandler;
Expand All @@ -52,6 +54,9 @@
*/
public final class ResourceInitializer {

private static final StructuredLogger LOGGER =
StructuredLoggerFactory.internalLogger(ResourceInitializer.class);

private final ResourceHandlers handlers;
private final ComponentValidator componentValidator;

Expand Down Expand Up @@ -86,6 +91,10 @@ public static ResourceInitializer resourceInitializer(final ResourceHandlers han
* @param components components to search for resources.
*/
public void init(final Collection<? extends ComponentDescriptor> components) {
LOGGER.debug(
"Initializing resources",
log -> log.with("stage", "init").with("components", componentNames(components)));

ensureResources(
groupById(
components,
Expand All @@ -101,6 +110,10 @@ public void init(final Collection<? extends ComponentDescriptor> components) {
* @param components components to search for resources.
*/
public void service(final Collection<? extends ComponentDescriptor> components) {
LOGGER.debug(
"Initializing resources",
log -> log.with("stage", "service").with("components", componentNames(components)));

ensureResources(
groupById(
components,
Expand All @@ -122,6 +135,13 @@ public void test(
final Collection<? extends ComponentDescriptor> componentsUnderTest,
final Collection<? extends ComponentDescriptor> otherComponents) {

LOGGER.debug(
"Initializing resources",
log ->
log.with("stage", "test")
.with("components_under_test", componentNames(componentsUnderTest))
.with("other_components", componentNames(otherComponents)));

final Map<URI, List<ResourceDescriptor>> unowned =
groupById(
componentsUnderTest,
Expand Down Expand Up @@ -221,6 +241,11 @@ private static String formatResource(final ResourceDescriptor descriptor) {
return "(" + CodeLocation.codeLocation(descriptor) + ") " + descriptor;
}

private static List<String> componentNames(
final Collection<? extends ComponentDescriptor> components) {
return components.stream().map(ComponentDescriptor::name).collect(Collectors.toList());
}

private static class ResourceDescriptorMismatchException extends RuntimeException {
ResourceDescriptorMismatchException(
final String msg, final List<? extends ResourceDescriptor> descriptors) {
Expand Down

0 comments on commit 92d0efc

Please sign in to comment.