r4350 - in trunk: . src/main/java/fr/ifremer/isisfish/logging src/main/resources
Author: echatellier Date: 2016-06-18 09:52:08 +0200 (Sat, 18 Jun 2016) New Revision: 4350 Url: http://forge.codelutin.com/projects/isis-fish/repository/revisions/4350 Log: Fix log level filtering Modified: trunk/pom.xml trunk/src/main/java/fr/ifremer/isisfish/logging/SimulationThresholdFilter.java trunk/src/main/resources/log4j2.xml Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2016-06-15 09:26:00 UTC (rev 4349) +++ trunk/pom.xml 2016-06-18 07:52:08 UTC (rev 4350) @@ -242,7 +242,7 @@ <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-core</artifactId> - <version>2.5</version> + <version>2.6.1</version> <scope>compile</scope> </dependency> @@ -249,7 +249,7 @@ <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-api</artifactId> - <version>2.5</version> + <version>2.6.1</version> <scope>compile</scope> </dependency> @@ -256,7 +256,7 @@ <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-jcl</artifactId> - <version>2.5</version> + <version>2.6.1</version> <scope>runtime</scope> </dependency> @@ -263,7 +263,7 @@ <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-slf4j-impl</artifactId> - <version>2.5</version> + <version>2.6.1</version> <scope>runtime</scope> </dependency> Modified: trunk/src/main/java/fr/ifremer/isisfish/logging/SimulationThresholdFilter.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/logging/SimulationThresholdFilter.java 2016-06-15 09:26:00 UTC (rev 4349) +++ trunk/src/main/java/fr/ifremer/isisfish/logging/SimulationThresholdFilter.java 2016-06-18 07:52:08 UTC (rev 4350) @@ -48,6 +48,8 @@ import fr.ifremer.isisfish.datastore.SimulationPlanStorage; import fr.ifremer.isisfish.datastore.SimulatorStorage; +import java.util.Map; + /** * Filter always available in log4j configuration that filter simulation log depending of simulation * log level configuration. @@ -56,15 +58,25 @@ public final class SimulationThresholdFilter extends AbstractFilter { private Level defaultThreshold = Level.ERROR; - /** Simulation id. Present in MDC context only if a simulation is running. */ + /** + * Simulation id. Present in MDC context only if a simulation is running. + */ public static final String SIMULATION_ID = "simulationId"; - /** Simulation log file for lof4j file appender (only if simulationId is defined) */ + /** + * Simulation log file for lof4j file appender (only if simulationId is defined) + */ public static final String SIMULATION_LOG_FILE = "simulationLogFile"; - /** {@code fr.ifremer.isisfish} package log level. */ + /** + * {@code fr.ifremer.isisfish} package log level. + */ public static final String SIMUALTION_APPLICATION_LEVEL = "simulationApplicationLevel"; - /** {@code org.nuiton} package log level. */ + /** + * {@code org.nuiton} package log level. + */ public static final String SIMULATION_LIB_LEVEL = "simulationLibLevel"; - /** Script log level. */ + /** + * Script log level. + */ public static final String SIMULATION_SCRIPT_LEVEL = "simulationScriptLevel"; private SimulationThresholdFilter(final Level defaultLevel, final Result onMatch, final Result onMismatch) { @@ -75,33 +87,33 @@ @Override public Result filter(final Logger logger, final Level level, final Marker marker, final String msg, final Object... params) { - return filter(logger.getName(), level); + return filter(logger.getName(), level, ThreadContext.getContext()); } @Override public Result filter(final Logger logger, final Level level, final Marker marker, final Object msg, final Throwable t) { - return filter(logger.getName(), level); + return filter(logger.getName(), level, ThreadContext.getContext()); } @Override public Result filter(final Logger logger, final Level level, final Marker marker, final Message msg, final Throwable t) { - return filter(logger.getName(), level); + return filter(logger.getName(), level, ThreadContext.getContext()); } @Override public Result filter(final LogEvent event) { - return filter(event.getLoggerFqcn(), event.getLevel()); + return filter(event.getLoggerFqcn(), event.getLevel(), event.getContextMap()); } - private Result filter(final String loggerFqcn, final Level level) { + private Result filter(final String loggerFqcn, final Level level, final Map<String, String> contextMap) { - String simulationId = ThreadContext.get("simulationId"); + String simulationId = contextMap.get("simulationId"); Result result; - // so simulation, no filtering + // so simulation, no specific filtering (neutral) if (simulationId == null) { result = Result.NEUTRAL; } else { @@ -108,9 +120,9 @@ Level ctxLevel = defaultThreshold; if (loggerFqcn.startsWith("fr.ifremer.isisfish")) { - ctxLevel = Level.getLevel(ThreadContext.get("simulationApplicationLevel")); + ctxLevel = Level.getLevel(contextMap.get("simulationApplicationLevel")); } else if (loggerFqcn.startsWith("org.nuiton")) { - ctxLevel = Level.getLevel(ThreadContext.get("simulationLibLevel")); + ctxLevel = Level.getLevel(contextMap.get("simulationLibLevel")); } else if (StringUtils.startsWithAny(loggerFqcn, ExportStorage.EXPORT_PATH, FormuleStorage.FORMULE_PATH, @@ -122,7 +134,7 @@ SensitivityExportStorage.SENSITIVITY_EXPORT_PATH, SimulationPlanStorage.SIMULATION_PLAN_PATH, SimulatorStorage.SIMULATOR_PATH)) { - ctxLevel = Level.getLevel(ThreadContext.get("simulationScriptLevel")); + ctxLevel = Level.getLevel(contextMap.get("simulationScriptLevel")); } result = level.isMoreSpecificThan(ctxLevel) ? onMatch : onMismatch; @@ -133,9 +145,10 @@ /** * Create the DynamicThresholdFilter. + * * @param defaultThreshold The default Level. - * @param onMatch The action to perform if a match occurs. - * @param onMismatch The action to perform if no match occurs. + * @param onMatch The action to perform if a match occurs. + * @param onMismatch The action to perform if no match occurs. * @return The DynamicThresholdFilter. */ @PluginFactory Modified: trunk/src/main/resources/log4j2.xml =================================================================== (Binary files differ)
participants (1)
-
echatellier@users.forge.codelutin.com