Skip to content

Commit

Permalink
Merge pull request #154 from jamezp/LOGMGR-181
Browse files Browse the repository at this point in the history
[LOGMGR-181] Add the useParentFilters property to the LoggerConfigura…
  • Loading branch information
jamezp authored Nov 21, 2017
2 parents a3e2ab6 + 18a1e2f commit f486cb0
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,53 @@ public interface LoggerConfiguration extends NamedConfigurable, HandlerContainin
*/
void setFilter(String expression, String value);

/**
* Determine whether parent filters will be used.
*
* @return the setting, or {@code null} to leave unconfigured
*/
Boolean getUseParentFilters();

/**
* Returns the value that may be an expression.
*
* @return the setting, or {@code null} to leave unconfigured as a value expression
*/
ValueExpression<Boolean> getUseParentFiltersValueExpression();

/**
* Set whether to use parent filters. A value of {@code null} indicates that the value should be left
* unconfigured.
*
* @param value whether to use parent filters
*/
void setUseParentFilters(Boolean value);

/**
* Set whether to use parent filters.
*
* @param expression the expression value used to resolve the setting
*
* @see #setUseParentFilters(Boolean)
* @see ValueExpression
*/
void setUseParentFilters(String expression);

/**
* Set whether to use parent filters.
* <p>
* This method will not parse the expression for the value and instead use the {@code value} parameter for the
* setting on the logger.
* </p>
*
* @param expression the expression
* @param value the value to set the setting to
*
* @see #setUseParentFilters(Boolean)
* @see ValueExpression
*/
void setUseParentFilters(String expression, Boolean value);

/**
* Determine whether parent handlers will be used.
*
Expand All @@ -68,7 +115,7 @@ public interface LoggerConfiguration extends NamedConfigurable, HandlerContainin
Boolean getUseParentHandlers();

/**
* Returns a filter that may be an expression.
* Returns the value that may be an expression.
*
* @return the setting, or {@code null} to leave unconfigured as a value expression
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
*/
final class LoggerConfigurationImpl extends AbstractBasicConfiguration<Logger, LoggerConfigurationImpl> implements LoggerConfiguration {
private ValueExpression<String> filter;
private ValueExpression<Boolean> useParentFilters;
private ValueExpression<Boolean> useParentHandlers;
private ValueExpression<String> level;
private final List<String> handlerNames = new ArrayList<String>(0);
Expand Down Expand Up @@ -86,6 +87,55 @@ public void rollback() {
});
}

@Override
public Boolean getUseParentFilters() {
return getUseParentFiltersValueExpression().getResolvedValue();
}

@Override
public ValueExpression<Boolean> getUseParentFiltersValueExpression() {
return useParentFilters;
}

@Override
public void setUseParentFilters(final Boolean value) {
setUseParentFilters(new ValueExpressionImpl<>(null, value));
}

@Override
public void setUseParentFilters(final String expression) {
setUseParentFilters(ValueExpression.BOOLEAN_RESOLVER.resolve(expression));
}

@Override
public void setUseParentFilters(final String expression, final Boolean value) {
setUseParentFilters(new ValueExpressionImpl<>(expression, value));
}

private void setUseParentFilters(final ValueExpression<Boolean> valueExpression) {
final ValueExpression<Boolean> oldUseParentFilters = this.useParentFilters;
this.useParentFilters = valueExpression;
final Boolean useParentFilters = valueExpression.getResolvedValue();
final LogContextConfigurationImpl configuration = getConfiguration();
configuration.addAction(new ConfigAction<Void>() {
public Void validate() throws IllegalArgumentException {
return null;
}

public void applyPreCreate(final Void param) {
}

public void applyPostCreate(final Void param) {
if (useParentFilters != null)
configuration.getLoggerRefs().get(getName()).setUseParentFilters(useParentFilters);
}

public void rollback() {
LoggerConfigurationImpl.this.useParentFilters = oldUseParentFilters;
}
});
}


public Boolean getUseParentHandlers() {
return getUseParentHandlersValueExpression().getResolvedValue();
Expand Down

0 comments on commit f486cb0

Please sign in to comment.