use of org.pentaho.di.core.logging.LogMessageInterface in project pentaho-cassandra-plugin by pentaho.
the class StepMockHelper method redirectLog.
/**
* In case you need to use log methods during the tests
* use redirectLog method after creating new StepMockHelper object.
* Examples:
* stepMockHelper.redirectLog( System.out, LogLevel.ROWLEVEL );
* stepMockHelper.redirectLog( new FileOutputStream("log.txt"), LogLevel.BASIC );
*/
public void redirectLog(final OutputStream out, LogLevel channelLogLevel) {
final LogChannel log = spy(new LogChannel(this.getClass().getName(), true));
log.setLogLevel(channelLogLevel);
when(logChannelInterfaceFactory.create(any(), any(LoggingObjectInterface.class))).thenReturn(log);
doAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
Object[] args = invocation.getArguments();
LogLevel logLevel = (LogLevel) args[1];
LogLevel channelLogLevel = log.getLogLevel();
if (!logLevel.isVisible(channelLogLevel)) {
// not for our eyes.
return null;
}
if (channelLogLevel.getLevel() >= logLevel.getLevel()) {
LogMessageInterface logMessage = (LogMessageInterface) args[0];
out.write(logMessage.getMessage().getBytes());
out.write('\n');
out.write('\r');
out.flush();
return true;
}
return false;
}
}).when(log).println((LogMessageInterface) anyObject(), (LogLevel) anyObject());
}
use of org.pentaho.di.core.logging.LogMessageInterface in project pentaho-kettle by pentaho.
the class StepMockHelper method redirectLog.
/**
* In case you need to use log methods during the tests
* use redirectLog method after creating new StepMockHelper object.
* Examples:
* stepMockHelper.redirectLog( System.out, LogLevel.ROWLEVEL );
* stepMockHelper.redirectLog( new FileOutputStream("log.txt"), LogLevel.BASIC );
*/
public void redirectLog(final OutputStream out, LogLevel channelLogLevel) {
final LogChannel log = spy(new LogChannel(this.getClass().getName(), true));
log.setLogLevel(channelLogLevel);
when(logChannelInterfaceFactory.create(any(), any(LoggingObjectInterface.class))).thenReturn(log);
doAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
Object[] args = invocation.getArguments();
LogLevel logLevel = (LogLevel) args[1];
LogLevel channelLogLevel = log.getLogLevel();
if (!logLevel.isVisible(channelLogLevel)) {
// not for our eyes.
return null;
}
if (channelLogLevel.getLevel() >= logLevel.getLevel()) {
LogMessageInterface logMessage = (LogMessageInterface) args[0];
out.write(logMessage.getMessage().getBytes());
out.write('\n');
out.write('\r');
out.flush();
return true;
}
return false;
}
}).when(log).println((LogMessageInterface) anyObject(), (LogLevel) anyObject());
}
Aggregations