From 482e72b9f9fe20ced80a7ff40742029ca7a8f000 Mon Sep 17 00:00:00 2001 From: Vladimir Orany Date: Thu, 7 Oct 2021 14:07:16 +0200 Subject: [PATCH] [branch ch52131] Log warning when snitches id is not set (#4) * Log warning when snitches id is not set * removed unused import --- .../micronaut/snitch/DefaultSnitchFactory.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/libs/micronaut-snitch/src/main/java/com/agorapulse/micronaut/snitch/DefaultSnitchFactory.java b/libs/micronaut-snitch/src/main/java/com/agorapulse/micronaut/snitch/DefaultSnitchFactory.java index 83be6de..c243110 100644 --- a/libs/micronaut-snitch/src/main/java/com/agorapulse/micronaut/snitch/DefaultSnitchFactory.java +++ b/libs/micronaut-snitch/src/main/java/com/agorapulse/micronaut/snitch/DefaultSnitchFactory.java @@ -18,6 +18,8 @@ package com.agorapulse.micronaut.snitch; import io.micronaut.context.annotation.*; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import javax.inject.Named; import javax.inject.Singleton; @@ -28,6 +30,8 @@ @Factory public class DefaultSnitchFactory { + private static final Logger LOGGER = LoggerFactory.getLogger(DefaultSnitchFactory.class); + @EachBean(SnitchJobConfiguration.class) @Requires(property = "snitches.jobs") public SnitchService snitchService(SnitchClient client, SnitchJobConfiguration configuration) { @@ -49,7 +53,11 @@ public SnitchService defaultSnitchService(SnitchClient client, @Value("${snitche @Singleton @Named("default") @Requires(missingProperty = "snitches.id") - public SnitchService noopSnitchService() { + public SnitchService noopSnitchService(@Value("${snitches.disabled:false}") boolean snitchesDisabled) { + if (!snitchesDisabled) { + LOGGER.warn("Micronaut Snitch is not configured! Please set snitches.id configuration property or set snitches.disabled to true to ignore this warning."); + } + return NoopSnitchService.INSTANCE; }