use of org.apache.commons.logging.Log in project ant by apache.
the class CommonsLoggingListener method getLog.
private Log getLog(String cat, String suffix) {
if (suffix != null) {
suffix = suffix.replace('.', '-');
suffix = suffix.replace(' ', '-');
cat = cat + "." + suffix;
}
final PrintStream tmpOut = System.out;
final PrintStream tmpErr = System.err;
System.setOut(out);
System.setErr(err);
if (!initialized) {
try {
logFactory = LogFactory.getFactory();
} catch (final LogConfigurationException e) {
e.printStackTrace(System.err);
return null;
}
}
initialized = true;
final Log log = logFactory.getInstance(cat);
System.setOut(tmpOut);
System.setErr(tmpErr);
return log;
}
use of org.apache.commons.logging.Log in project ant by apache.
the class CommonsLoggingListener method targetFinished.
/**
* @see BuildListener#targetFinished
* {@inheritDoc}.
*/
@Override
public void targetFinished(final BuildEvent event) {
if (initialized) {
final String targetName = event.getTarget().getName();
final Log log = getLog(TARGET_LOG, event.getTarget().getName());
if (event.getException() == null) {
realLog(log, "Target end: " + targetName, Project.MSG_DEBUG, null);
} else {
realLog(log, "Target \"" + targetName + "\" finished with error.", Project.MSG_ERR, event.getException());
}
}
}
use of org.apache.commons.logging.Log in project ant by apache.
the class CommonsLoggingListener method taskStarted.
/**
* @see BuildListener#taskStarted
* {@inheritDoc}.
*/
@Override
public void taskStarted(final BuildEvent event) {
if (initialized) {
final Task task = event.getTask();
Object real = task;
if (task instanceof UnknownElement) {
final Object realObj = ((UnknownElement) task).getTask();
if (realObj != null) {
real = realObj;
}
}
final Log log = getLog(real.getClass().getName(), null);
if (log.isTraceEnabled()) {
realLog(log, "Task \"" + task.getTaskName() + "\" started ", Project.MSG_VERBOSE, null);
}
}
}
use of org.apache.commons.logging.Log in project ant by apache.
the class CommonsLoggingListener method targetStarted.
/**
* @see BuildListener#targetStarted
* {@inheritDoc}.
*/
@Override
public void targetStarted(final BuildEvent event) {
if (initialized) {
final Log log = getLog(TARGET_LOG, event.getTarget().getName());
// Since task log category includes target, we don't really
// need this message
realLog(log, "Start: " + event.getTarget().getName(), Project.MSG_VERBOSE, null);
}
}
use of org.apache.commons.logging.Log in project ant by apache.
the class CommonsLoggingListener method messageLogged.
/**
* @see BuildListener#messageLogged
* {@inheritDoc}.
*/
@Override
public void messageLogged(final BuildEvent event) {
if (initialized) {
Object categoryObject = event.getTask();
String categoryString;
String categoryDetail = null;
if (categoryObject == null) {
categoryObject = event.getTarget();
if (categoryObject == null) {
categoryString = PROJECT_LOG;
categoryDetail = event.getProject().getName();
} else {
categoryString = TARGET_LOG;
categoryDetail = event.getTarget().getName();
}
} else {
// It's a task - append the target
if (event.getTarget() != null) {
categoryString = categoryObject.getClass().getName();
categoryDetail = event.getTarget().getName();
} else {
categoryString = categoryObject.getClass().getName();
}
}
final Log log = getLog(categoryString, categoryDetail);
final int priority = event.getPriority();
final String message = event.getMessage();
realLog(log, message, priority, null);
}
}
Aggregations