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

[LOGMGR-181] Add the useParentFilters property to the LoggerConfigura… #154

Merged
merged 1 commit into from
Nov 21, 2017
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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