Skip to content

Commit

Permalink
Fix usage of AntTaskLogger.
Browse files Browse the repository at this point in the history
Motivation
----------

Liquibase has a fairly new logging abstraction and it wasn't entirely working with the Ant tasks. The tasks were reverting to standard out logging which might make it difficult to control log levels correctly in Ant tasks.

Modifications
-------------

I leveraged the new Scope system (pretty neat!) to add the AntLogService manually. This log service creates the AntTaskLogger correctly so the logger delegates to Ant's logger again.

Result
------

The ant tasks once again handle Liquibase logs correctly.

(cherry picked from commit 499ac6a)
  • Loading branch information
mattbertolini authored and nvoxland committed Oct 9, 2020
1 parent 39a2e1e commit 93a8e57
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
package liquibase.integration.ant;

import liquibase.integration.ant.AntTaskLogger;
import liquibase.logging.LogService;
import liquibase.logging.Logger;
import liquibase.logging.core.AbstractLogService;
import org.apache.tools.ant.Task;

import java.util.logging.Level;

/**
* An implementation of the Liquibase LogService that logs all messages to the given Ant task. This should only be used
* inside of Ant tasks.
*/
public final class AntTaskLogService extends AbstractLogService {

private AntTaskLogger logger;
private final AntTaskLogger logger;

public AntTaskLogService(Task task) {
logger = new AntTaskLogger(task, this.filter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
public abstract class BaseLiquibaseTask extends Task {
private static ResourceBundle coreBundle = getBundle("liquibase/i18n/liquibase-core");

private final Map<String, Object> scopeValues = new HashMap<>();

private AntClassLoader classLoader;
private Liquibase liquibase;

Expand All @@ -46,7 +48,7 @@ public BaseLiquibaseTask() {

@Override
public void init() throws BuildException {
// LogService.setLoggerFactory(new AntTaskLogService(this));
scopeValues.put(Scope.Attr.logService.name(), new AntTaskLogService(this));
classpath = new Path(getProject());
}

Expand All @@ -61,7 +63,6 @@ public final void execute() throws BuildException {
final Database[] database = {null};
try {
ResourceAccessor resourceAccessor = createResourceAccessor(classLoader);
Map<String, Object> scopeValues = new HashMap<>();
scopeValues.put(Scope.Attr.resourceAccessor.name(), resourceAccessor);
scopeValues.put(Scope.Attr.classLoader.name(), classLoader);

Expand Down

0 comments on commit 93a8e57

Please sign in to comment.