All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.dita.dost.log.DITAOTAntLogger Maven / Gradle / Ivy

/*
 * This file is part of the DITA Open Toolkit project.
 *
 * Copyright 2011 Jarno Elovirta
 *
 * See the accompanying LICENSE file for applicable license.
 */
package org.dita.dost.log;

import org.apache.tools.ant.Project;
import org.apache.tools.ant.Target;
import org.apache.tools.ant.Task;

/**
 * Logger proxy to Ant logger.
 *
 * @author Jarno Elovirta
 */
public final class DITAOTAntLogger extends AbstractLogger {

  public static final String USE_COLOR = "dita.use-color";

  private final Project project;
  private Task task;
  private Target target;

  /**
   * Construct a new logger that forwards messages to Ant project logger.
   * @param project Ant project to log to
   * @throws NullPointerException if project is {@code null}
   */
  public DITAOTAntLogger(final Project project) {
    super();
    if (project == null) {
      throw new NullPointerException();
    }
    this.project = project;
    this.useColor = Boolean.parseBoolean(project.getProperty(USE_COLOR));
  }

  /**
   * Set log message source task.
   * @param task logging task
   */
  public void setTask(final Task task) {
    this.task = task;
  }

  /**
   * Set log message source target.
   * @param target logging target
   */
  public void setTarget(final Target target) {
    this.target = target;
  }

  @Override
  public void log(final String msg, final Throwable t, final int level) {
    if (task != null) {
      project.log(task, msg, t, level);
    } else if (target != null) {
      project.log(target, msg, t, level);
    } else {
      project.log(msg, t, level);
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy