use of org.apache.openejb.log.LoggerCreator in project tomee by apache.
the class LoggingSqlTest method checkOutput.
@Test
public void checkOutput() throws Exception {
final Logger logger = Logger.getInstance(LogCategory.OPENEJB_SQL, LoggingPreparedSqlStatement.class);
final JuliLogStream stream = JuliLogStream.class.cast(Reflections.get(logger, "logStream"));
final LoggerCreator julCreator = LoggerCreator.class.cast(Reflections.get(stream, "logger"));
final java.util.logging.Logger actualLogger = julCreator.call();
final Collection<String> msgs = new LinkedList<>();
final Handler handler = new Handler() {
@Override
public void publish(final LogRecord record) {
msgs.add(record.getMessage());
}
@Override
public void flush() {
// no-op
}
@Override
public void close() throws SecurityException {
// no-op
}
};
actualLogger.addHandler(handler);
final Connection c = ds.getConnection();
final PreparedStatement preparedStatement = c.prepareStatement("select 1 from INFORMATION_SCHEMA.SYSTEM_USERS");
preparedStatement.execute();
preparedStatement.close();
c.close();
actualLogger.removeHandler(handler);
assertEquals(1, msgs.size());
final String msg = msgs.iterator().next();
assertTrue(msg.contains("select 1 from INFORMATION_SCHEMA.SYSTEM_USERS"));
assertTrue(msg.contains("stack: -> org.apache.openejb.resource.jdbc.logging.LoggingSqlTest.checkOutput:83"));
}
use of org.apache.openejb.log.LoggerCreator in project tomee by apache.
the class LoggingJAXRSCommons method getLooger.
protected java.util.logging.Logger getLooger() throws Exception {
final Logger logger = Logger.getInstance(LogCategory.OPENEJB_RS, RESTService.class);
final LogStreamAsync stream = LogStreamAsync.class.cast(Reflections.get(logger, "logStream"));
final JuliLogStream ls = JuliLogStream.class.cast(Reflections.get(stream, "ls"));
final LoggerCreator julCreator = LoggerCreator.class.cast(Reflections.get(ls, "logger"));
return julCreator.call();
}
Aggregations