use of org.apache.geode.internal.logging.PureLogWriter in project geode by apache.
the class PartitionedRegionDUnitTestCase method setLogLevel.
/**
* Sets the loglevel for the provided log writer
*
* @param l the {@link LogWriter}
* @param logLevl the new log level as specified in {@link LogWriterImpl}
* @return the old log level
*/
public static int setLogLevel(LogWriter l, int logLevl) {
int ret = -1;
l.config("PartitionedRegionDUnitTest attempting to set log level on LogWriter instance class:" + l.getClass().getName());
if (l instanceof PureLogWriter) {
PureLogWriter pl = (PureLogWriter) l;
ret = pl.getLogWriterLevel();
l.config("PartitiionedRegionDUnitTest forcing log level to " + LogWriterImpl.levelToString(logLevl) + " from " + LogWriterImpl.levelToString(ret));
pl.setLevel(logLevl);
}
return ret;
}
use of org.apache.geode.internal.logging.PureLogWriter in project geode by apache.
the class LogWriterAppenderJUnitTest method testLogWriterLevels.
/**
* Verifies that logging occurs at the levels set in the LogWriter
*/
@Test
public void testLogWriterLevels() throws IOException {
// this.getClass().getName();
final String loggerName = LogService.MAIN_LOGGER_NAME;
// Force logging to be initialized
LogService.getLogger();
// Create the LogWriterLogger that will be attached to the appender
final LogWriterLogger logWriterLogger = LogWriterLogger.create(loggerName, false);
logWriterLogger.setLevel(Level.INFO);
// Create the appender
final StringWriter stringWriter = new StringWriter();
final PureLogWriter logWriter = new PureLogWriter(InternalLogWriter.FINEST_LEVEL, new PrintWriter(stringWriter), "");
final AppenderContext[] contexts = new AppenderContext[2];
// root context
contexts[0] = LogService.getAppenderContext();
// "org.apache"
contexts[1] = LogService.getAppenderContext(LogService.BASE_LOGGER_NAME);
// context
this.appender = LogWriterAppender.create(contexts, loggerName, logWriter, null);
logWriter.finest("DIRECT MESSAGE");
assertTrue(Pattern.compile(".*\\[finest .*DIRECT MESSAGE.*", Pattern.DOTALL).matcher(stringWriter.toString()).matches());
stringWriter.getBuffer().setLength(0);
LogEvent event = Log4jLogEvent.newBuilder().setLevel(Level.INFO).setLoggerFqcn("NAME").setLoggerName("NAME").setMessage(new ParameterizedMessage("LOGEVENT MESSAGE")).build();
this.appender.append(event);
assertTrue(Pattern.compile(".*\\[info .*LOGEVENT MESSAGE.*", Pattern.DOTALL).matcher(stringWriter.toString()).matches());
stringWriter.getBuffer().setLength(0);
logWriterLogger.finest("FINEST MESSAGE");
assertFalse(Pattern.compile(".*\\[finest .*FINEST MESSAGE.*", Pattern.DOTALL).matcher(stringWriter.toString()).matches());
stringWriter.getBuffer().setLength(0);
logWriterLogger.fine("FINE MESSAGE");
assertFalse(Pattern.compile(".*\\[fine .*FINE MESSAGE.*", Pattern.DOTALL).matcher(stringWriter.toString()).matches());
stringWriter.getBuffer().setLength(0);
logWriterLogger.info("INFO MESSAGE");
assertTrue(stringWriter.toString(), Pattern.compile(".*\\[info .*INFO MESSAGE.*", Pattern.DOTALL).matcher(stringWriter.toString()).matches());
stringWriter.getBuffer().setLength(0);
// Change the level
logWriterLogger.setLevel(Level.DEBUG);
logWriterLogger.finest("FINEST MESSAGE");
assertFalse(Pattern.compile(".*\\[finest .*FINEST MESSAGE.*", Pattern.DOTALL).matcher(stringWriter.toString()).matches());
stringWriter.getBuffer().setLength(0);
logWriterLogger.fine("FINE MESSAGE");
assertTrue(Pattern.compile(".*\\[fine .*FINE MESSAGE.*", Pattern.DOTALL).matcher(stringWriter.toString()).matches());
stringWriter.getBuffer().setLength(0);
logWriterLogger.info("INFO MESSAGE");
assertTrue(Pattern.compile(".*\\[info .*INFO MESSAGE.*", Pattern.DOTALL).matcher(stringWriter.toString()).matches());
stringWriter.getBuffer().setLength(0);
this.appender.destroy();
}
use of org.apache.geode.internal.logging.PureLogWriter in project geode by apache.
the class ProductUseLog method createLogWriter.
private synchronized void createLogWriter() {
FileOutputStream fos;
try {
fos = new FileOutputStream(productUseLogFile, true);
} catch (FileNotFoundException ex) {
String s = LocalizedStrings.InternalDistributedSystem_COULD_NOT_OPEN_LOG_FILE_0.toLocalizedString(productUseLogFile);
throw new GemFireIOException(s, ex);
}
PrintStream out = new PrintStream(fos);
this.logWriter = new PureLogWriter(this.logLevel, out);
}
use of org.apache.geode.internal.logging.PureLogWriter in project geode by apache.
the class PartitionedRegionDUnitTest method setLogLevel.
public static int setLogLevel(LogWriter l, int logLevl) {
int ret = -1;
if (l instanceof PureLogWriter) {
PureLogWriter pl = (PureLogWriter) l;
ret = pl.getLogWriterLevel();
pl.setLevel(logLevl);
}
return ret;
}
use of org.apache.geode.internal.logging.PureLogWriter in project geode by apache.
the class LogWriterAppenderJUnitTest method testAppenderToConfigHandling.
/**
* Verifies that the appender is correctly added and removed from the Log4j configuration and that
* when the configuration is changed the appender is still there.
*/
@Test
public void testAppenderToConfigHandling() throws IOException {
LogService.setBaseLogLevel(Level.TRACE);
final AppenderContext rootContext = LogService.getAppenderContext();
// Find out home many appenders exist before we get started
final int startingSize = rootContext.getLoggerConfig().getAppenders().size();
// System.out.println("Appenders " +
// context.getLoggerConfig().getAppenders().values().toString());
// Create the appender and verify it's part of the configuration
final StringWriter stringWriter = new StringWriter();
final PureLogWriter logWriter = new PureLogWriter(InternalLogWriter.FINE_LEVEL, new PrintWriter(stringWriter), "");
final AppenderContext[] contexts = new AppenderContext[2];
// root context
contexts[0] = rootContext;
// "org.apache"
contexts[1] = LogService.getAppenderContext(LogService.BASE_LOGGER_NAME);
// context
this.appender = LogWriterAppender.create(contexts, LogService.MAIN_LOGGER_NAME, logWriter, null);
assertEquals(rootContext.getLoggerConfig().getAppenders().values().toString(), startingSize + 1, rootContext.getLoggerConfig().getAppenders().size());
assertTrue(rootContext.getLoggerConfig().getAppenders().containsKey(this.appender.getName()));
// Modify the config and verify that the appender still exists
assertEquals(Level.TRACE, LogService.getLogger(LogService.BASE_LOGGER_NAME).getLevel());
LogService.setBaseLogLevel(Level.DEBUG);
assertEquals(Level.DEBUG, LogService.getLogger(LogService.BASE_LOGGER_NAME).getLevel());
assertTrue(rootContext.getLoggerConfig().getAppenders().containsKey(this.appender.getName()));
// Destroy the appender and verify that it was removed from log4j
this.appender.destroy();
assertEquals(rootContext.getLoggerConfig().getAppenders().values().toString(), startingSize, rootContext.getLoggerConfig().getAppenders().size());
assertFalse(rootContext.getLoggerConfig().getAppenders().containsKey(this.appender.getName()));
}
Aggregations