Murtadha Hubail has submitted this change and it was merged. Change subject: [ASTERIXDB-1564][CONF] Replace Remaining Usage of JUL ......................................................................
[ASTERIXDB-1564][CONF] Replace Remaining Usage of JUL - user model changes: no - storage format changes: no - interface changes: no Details: - Replace remaining usage of java.util.logging by Log4j2. Change-Id: I894348b09a862693ae31de7c2f4768877a5297db Reviewed-on: https://asterix-gerrit.ics.uci.edu/2254 Integration-Tests: Jenkins <[email protected]> Tested-by: Jenkins <[email protected]> Contrib: Jenkins <[email protected]> Reviewed-by: Michael Blow <[email protected]> --- M asterixdb/asterix-replication/src/main/java/org/apache/asterix/replication/messaging/DeleteFileTask.java M asterixdb/asterix-replication/src/main/java/org/apache/asterix/replication/messaging/ReplicateFileTask.java M asterixdb/asterix-replication/src/main/java/org/apache/asterix/replication/storage/PartitionReplica.java M asterixdb/asterix-server/src/test/java/org/apache/asterix/server/test/MetadataReplicationIT.java M hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/util/IoUtil.java M hyracks-fullstack/hyracks/hyracks-test-support/pom.xml M hyracks-fullstack/hyracks/hyracks-test-support/src/main/java/org/apache/hyracks/storage/am/common/AbstractIndexLifecycleTest.java M hyracks-fullstack/hyracks/hyracks-util/pom.xml A hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/Log4j2Monitor.java D hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/RuntimeLogsMonitor.java M hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/trace/Tracer.java M hyracks-fullstack/hyracks/hyracks-util/src/test/java/org/apache/hyracks/util/trace/TraceTest.java 12 files changed, 128 insertions(+), 188 deletions(-) Approvals: Anon. E. Moose #1000171: Jenkins: Verified; ; Verified Michael Blow: Looks good to me, approved Objections: Jenkins: Violations found diff --git a/asterixdb/asterix-replication/src/main/java/org/apache/asterix/replication/messaging/DeleteFileTask.java b/asterixdb/asterix-replication/src/main/java/org/apache/asterix/replication/messaging/DeleteFileTask.java index ea43ee9..d4de3b7 100644 --- a/asterixdb/asterix-replication/src/main/java/org/apache/asterix/replication/messaging/DeleteFileTask.java +++ b/asterixdb/asterix-replication/src/main/java/org/apache/asterix/replication/messaging/DeleteFileTask.java @@ -24,7 +24,6 @@ import java.io.IOException; import java.io.OutputStream; import java.nio.file.Files; -import java.util.logging.Logger; import org.apache.asterix.common.api.INcApplicationContext; import org.apache.asterix.common.exceptions.ReplicationException; @@ -33,13 +32,15 @@ import org.apache.asterix.replication.functions.ReplicationProtocol; import org.apache.hyracks.api.exceptions.HyracksDataException; import org.apache.hyracks.api.io.IIOManager; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; /** * A task to delete a file on a replica if exists */ public class DeleteFileTask implements IReplicaTask { - private static final Logger LOGGER = Logger.getLogger(DeleteFileTask.class.getName()); + private static final Logger LOGGER = LogManager.getLogger(); private final String file; public DeleteFileTask(String file) { @@ -55,7 +56,7 @@ Files.delete(localFile.toPath()); LOGGER.info(() -> "Deleted file: " + localFile.getAbsolutePath()); } else { - LOGGER.warning(() -> "Requested to delete a non-existing file: " + localFile.getAbsolutePath()); + LOGGER.warn(() -> "Requested to delete a non-existing file: " + localFile.getAbsolutePath()); } ReplicationProtocol.sendAck(worker.getChannel(), worker.getReusableBuffer()); } catch (IOException e) { diff --git a/asterixdb/asterix-replication/src/main/java/org/apache/asterix/replication/messaging/ReplicateFileTask.java b/asterixdb/asterix-replication/src/main/java/org/apache/asterix/replication/messaging/ReplicateFileTask.java index 14e9180..45d8971 100644 --- a/asterixdb/asterix-replication/src/main/java/org/apache/asterix/replication/messaging/ReplicateFileTask.java +++ b/asterixdb/asterix-replication/src/main/java/org/apache/asterix/replication/messaging/ReplicateFileTask.java @@ -27,7 +27,6 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -import java.util.logging.Logger; import org.apache.asterix.common.api.INcApplicationContext; import org.apache.asterix.common.exceptions.ReplicationException; @@ -39,13 +38,15 @@ import org.apache.hyracks.api.exceptions.HyracksDataException; import org.apache.hyracks.api.io.FileReference; import org.apache.hyracks.api.io.IIOManager; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; /** * A task to replicate a file from a master replica */ public class ReplicateFileTask implements IReplicaTask { - private static final Logger LOGGER = Logger.getLogger(DeleteFileTask.class.getName()); + private static final Logger LOGGER = LogManager.getLogger(); private final String file; private final long size; diff --git a/asterixdb/asterix-replication/src/main/java/org/apache/asterix/replication/storage/PartitionReplica.java b/asterixdb/asterix-replication/src/main/java/org/apache/asterix/replication/storage/PartitionReplica.java index d9ce75e..b7fa49d 100644 --- a/asterixdb/asterix-replication/src/main/java/org/apache/asterix/replication/storage/PartitionReplica.java +++ b/asterixdb/asterix-replication/src/main/java/org/apache/asterix/replication/storage/PartitionReplica.java @@ -25,8 +25,6 @@ import java.io.IOException; import java.nio.ByteBuffer; import java.nio.channels.SocketChannel; -import java.util.logging.Level; -import java.util.logging.Logger; import org.apache.asterix.common.api.INcApplicationContext; import org.apache.asterix.common.exceptions.ReplicationException; @@ -37,6 +35,8 @@ import org.apache.hyracks.util.JSONUtil; import org.apache.hyracks.util.StorageUtil; import org.apache.hyracks.util.annotations.ThreadSafe; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonNode; @@ -46,7 +46,7 @@ @ThreadSafe public class PartitionReplica implements IPartitionReplica { - private static final Logger LOGGER = Logger.getLogger(PartitionReplica.class.getName()); + private static final Logger LOGGER = LogManager.getLogger(); private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); private static final int INITIAL_BUFFER_SIZE = StorageUtil.getIntSizeInBytes(4, StorageUtil.StorageUnit.KILOBYTE); private final INcApplicationContext appCtx; @@ -80,7 +80,7 @@ new ReplicaSynchronizer(appCtx, this).sync(); setStatus(IN_SYNC); } catch (Exception e) { - LOGGER.log(Level.SEVERE, e, () -> "Failed to sync replica " + this); + LOGGER.error(() -> "Failed to sync replica " + this, e); setStatus(DISCONNECTED); } finally { close(); diff --git a/asterixdb/asterix-server/src/test/java/org/apache/asterix/server/test/MetadataReplicationIT.java b/asterixdb/asterix-server/src/test/java/org/apache/asterix/server/test/MetadataReplicationIT.java index 445f53f..5ae6843 100644 --- a/asterixdb/asterix-server/src/test/java/org/apache/asterix/server/test/MetadataReplicationIT.java +++ b/asterixdb/asterix-server/src/test/java/org/apache/asterix/server/test/MetadataReplicationIT.java @@ -24,7 +24,6 @@ import java.util.Collection; import java.util.Map; import java.util.concurrent.TimeUnit; -import java.util.logging.Logger; import org.apache.asterix.test.base.RetainLogsRule; import org.apache.asterix.test.common.TestExecutor; @@ -34,6 +33,8 @@ import org.apache.hyracks.server.process.HyracksCCProcess; import org.apache.hyracks.server.process.HyracksNCServiceProcess; import org.apache.hyracks.server.process.HyracksVirtualCluster; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.junit.After; import org.junit.Before; import org.junit.Rule; @@ -88,7 +89,7 @@ .get("src", "test", "resources", "integrationts", "metadata_only_replication").toString() + File.separator; private static final String PATH_ACTUAL = "target" + File.separator + "ittest" + File.separator; - private static final Logger LOGGER = Logger.getLogger(MetadataReplicationIT.class.getName()); + private static final Logger LOGGER = LogManager.getLogger(); private static String reportPath = new File( StringUtils.join(new String[] { "target", "failsafe-reports" }, File.separator)).getAbsolutePath(); diff --git a/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/util/IoUtil.java b/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/util/IoUtil.java index 329b24d..396c026 100644 --- a/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/util/IoUtil.java +++ b/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/util/IoUtil.java @@ -23,13 +23,13 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.NoSuchFileException; -import java.util.logging.Level; -import java.util.logging.Logger; import org.apache.commons.io.FileUtils; import org.apache.hyracks.api.exceptions.ErrorCode; import org.apache.hyracks.api.exceptions.HyracksDataException; import org.apache.hyracks.api.io.FileReference; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; /** * This util class takes care of creation and deletion of files and directories @@ -38,7 +38,7 @@ public class IoUtil { public static final String FILE_NOT_FOUND_MSG = "Deleting non-existing file!"; - private static final Logger LOGGER = Logger.getLogger(IoUtil.class.getName()); + private static final Logger LOGGER = LogManager.getLogger(); private IoUtil() { } @@ -71,7 +71,7 @@ Files.delete(file.toPath()); } } catch (NoSuchFileException | FileNotFoundException e) { - LOGGER.log(Level.WARNING, FILE_NOT_FOUND_MSG + ": " + e.getMessage(), e); + LOGGER.warn(() -> FILE_NOT_FOUND_MSG + ": " + e.getMessage(), e); } catch (IOException e) { throw HyracksDataException.create(ErrorCode.CANNOT_DELETE_FILE, e, file.getAbsolutePath()); } diff --git a/hyracks-fullstack/hyracks/hyracks-test-support/pom.xml b/hyracks-fullstack/hyracks/hyracks-test-support/pom.xml index 6559308..fde7394 100644 --- a/hyracks-fullstack/hyracks/hyracks-test-support/pom.xml +++ b/hyracks-fullstack/hyracks/hyracks-test-support/pom.xml @@ -108,5 +108,9 @@ <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-api</artifactId> </dependency> + <dependency> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-core</artifactId> + </dependency> </dependencies> </project> diff --git a/hyracks-fullstack/hyracks/hyracks-test-support/src/main/java/org/apache/hyracks/storage/am/common/AbstractIndexLifecycleTest.java b/hyracks-fullstack/hyracks/hyracks-test-support/src/main/java/org/apache/hyracks/storage/am/common/AbstractIndexLifecycleTest.java index 8fc4275..ddb5717 100644 --- a/hyracks-fullstack/hyracks/hyracks-test-support/src/main/java/org/apache/hyracks/storage/am/common/AbstractIndexLifecycleTest.java +++ b/hyracks-fullstack/hyracks/hyracks-test-support/src/main/java/org/apache/hyracks/storage/am/common/AbstractIndexLifecycleTest.java @@ -18,16 +18,13 @@ */ package org.apache.hyracks.storage.am.common; -import java.nio.file.NoSuchFileException; -import java.util.logging.Level; -import java.util.logging.LogRecord; - import org.apache.hyracks.api.exceptions.HyracksDataException; import org.apache.hyracks.api.util.IoUtil; import org.apache.hyracks.storage.common.IIndex; -import org.apache.hyracks.util.RuntimeLogsMonitor; +import org.apache.hyracks.util.Log4j2Monitor; +import org.apache.logging.log4j.Level; +import org.apache.logging.log4j.core.config.Configurator; import org.junit.After; -import org.junit.AfterClass; import org.junit.Assert; import org.junit.Before; import org.junit.BeforeClass; @@ -49,12 +46,8 @@ @BeforeClass public static void startLogsMonitor() { - RuntimeLogsMonitor.monitor("org.apache.hyracks"); - } - - @AfterClass - public static void afterClass() { - RuntimeLogsMonitor.stop(); + Configurator.setLevel("org.apache.hyracks", Level.INFO); + Log4j2Monitor.start(); } @Before @@ -65,7 +58,7 @@ @Test public void validSequenceTest() throws Exception { - RuntimeLogsMonitor.reset(); + Log4j2Monitor.reset(); // Double create is invalid index.create(); Assert.assertTrue(persistentStateExists()); @@ -104,8 +97,7 @@ index.destroy(); Assert.assertFalse(persistentStateExists()); index.destroy(); - final LogRecord fileNotFoundWarnLog = new LogRecord(Level.WARNING, IoUtil.FILE_NOT_FOUND_MSG); - Assert.assertTrue(RuntimeLogsMonitor.count(fileNotFoundWarnLog) > 0); + Assert.assertTrue(Log4j2Monitor.count(IoUtil.FILE_NOT_FOUND_MSG) > 0); Assert.assertFalse(persistentStateExists()); } diff --git a/hyracks-fullstack/hyracks/hyracks-util/pom.xml b/hyracks-fullstack/hyracks/hyracks-util/pom.xml index 52ccf2f..c521f08 100644 --- a/hyracks-fullstack/hyracks/hyracks-util/pom.xml +++ b/hyracks-fullstack/hyracks/hyracks-util/pom.xml @@ -75,6 +75,10 @@ <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-api</artifactId> </dependency> + <dependency> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-core</artifactId> + </dependency> </dependencies> </project> diff --git a/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/Log4j2Monitor.java b/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/Log4j2Monitor.java new file mode 100644 index 0000000..34751b8 --- /dev/null +++ b/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/Log4j2Monitor.java @@ -0,0 +1,84 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.hyracks.util; + +import java.io.IOException; +import java.io.Writer; +import java.nio.CharBuffer; +import java.util.ArrayList; +import java.util.List; + +import org.apache.logging.log4j.Level; +import org.apache.logging.log4j.core.Appender; +import org.apache.logging.log4j.core.LoggerContext; +import org.apache.logging.log4j.core.appender.WriterAppender; +import org.apache.logging.log4j.core.config.Configuration; +import org.apache.logging.log4j.core.config.LoggerConfig; + +public class Log4j2Monitor { + + private static final List<String> logs = new ArrayList<>(); + + private Log4j2Monitor() { + } + + public static void start() { + final LoggerContext context = LoggerContext.getContext(false); + final Appender appender = WriterAppender.createAppender(null, null, new LogWriter(), "MEMORY", false, true); + appender.start(); + final Configuration config = context.getConfiguration(); + config.addAppender(appender); + for (final LoggerConfig loggerConfig : config.getLoggers().values()) { + loggerConfig.addAppender(appender, null, null); + } + config.getRootLogger().addAppender(appender, Level.ALL, null); + context.updateLoggers(); + } + + public static long count(String message) { + return logs.stream().filter(log -> log.contains(message)).count(); + } + + public static void reset() { + logs.clear(); + } + + public static List<String> getLogs() { + return logs; + } + + private static class LogWriter extends Writer { + + @Override + public void write(char[] buffer, int off, int len) { + logs.add(CharBuffer.wrap(buffer, off, len).toString()); + } + + @Override + public void flush() { + // no op + } + + @Override + public void close() throws IOException { + // no op + } + } +} \ No newline at end of file diff --git a/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/RuntimeLogsMonitor.java b/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/RuntimeLogsMonitor.java deleted file mode 100644 index d2eb7fd..0000000 --- a/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/RuntimeLogsMonitor.java +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.hyracks.util; - -import java.util.ArrayList; -import java.util.List; -import java.util.logging.Handler; -import java.util.logging.Level; -import java.util.logging.LogRecord; -import java.util.logging.Logger; - -/** - * RuntimeLogsMonitor is used to store the generated runtime logs in-memory - * and provides API to search the stored logs. - */ -public class RuntimeLogsMonitor { - - private static final InMemoryHandler IN_MEMORY_HANDLER = new InMemoryHandler(); - private static final List<Logger> MONITORED_LOGGERS = new ArrayList<>(); - private static List<LogRecord> logs; - - private RuntimeLogsMonitor() { - reset(); - } - - /** - * Starts monitoring the logger by storing its generated logs in-memory. By default - * only logs with level WARNING and above are stored - * - * @param loggerName - */ - public static void monitor(String loggerName) { - final Logger logger = Logger.getLogger(loggerName); - for (Handler handler : logger.getHandlers()) { - if (handler == IN_MEMORY_HANDLER) { - return; - } - } - MONITORED_LOGGERS.add(logger); - Logger.getLogger(loggerName).addHandler(IN_MEMORY_HANDLER); - } - - /** - * Discards any stored logs - */ - public static void reset() { - logs = new ArrayList<>(); - } - - /** - * Calculates the count based on {@code logRecord} level and message. - * if any stored log has the same level as {@code logRecord} and - * the log's message contains {@code logRecord} message, it is considered - * as an occurrence - * - * @param logRecord - * @return The number of found logs that match {@code logRecord} - */ - public static long count(LogRecord logRecord) { - return logs.stream() - .filter(storedLog -> storedLog.getLevel().equals(logRecord.getLevel()) && storedLog.getMessage() - .contains(logRecord.getMessage())).count(); - } - - /** - * Sets the stored logs minimum level - * - * @param lvl - */ - public static void setLevel(Level lvl) { - IN_MEMORY_HANDLER.setLevel(lvl); - } - - /** - * Stops monitoring any monitored loggers and discards any - * stored logs - */ - public static void stop() { - for (Logger logger : MONITORED_LOGGERS) { - logger.removeHandler(IN_MEMORY_HANDLER); - } - reset(); - MONITORED_LOGGERS.clear(); - } - - private static class InMemoryHandler extends Handler { - private InMemoryHandler() { - super.setLevel(Level.WARNING); - setFilter(record -> record.getLevel().intValue() >= getLevel().intValue()); - } - - @Override - public void publish(LogRecord lr) { - if (isLoggable(lr)) { - logs.add(lr); - } - } - - @Override - public void flush() { - // nothing to flush - } - - @Override - public void close() { - // nothing to close - } - } -} diff --git a/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/trace/Tracer.java b/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/trace/Tracer.java index 4c6f234..79922b7 100644 --- a/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/trace/Tracer.java +++ b/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/trace/Tracer.java @@ -23,17 +23,18 @@ import java.text.SimpleDateFormat; import java.util.Arrays; import java.util.Date; -import java.util.logging.Level; -import java.util.logging.Logger; import org.apache.hyracks.util.PidHelper; +import org.apache.logging.log4j.Level; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; /** * https://docs.google.com/document/d/1CvAClvFfyA5R-PhYUmn5OOQtYMH4h6I0nSsKchNAySU/edit */ public class Tracer implements ITracer { - public static final Logger LOGGER = Logger.getLogger(Tracer.class.getName()); + public static final Logger LOGGER = LogManager.getLogger(); protected static final Level TRACE_LOG_LEVEL = Level.INFO; protected static final String CAT = "Tracer"; @@ -48,7 +49,7 @@ public Tracer(String name, long categories, TraceCategoryRegistry registry) { final String traceLoggerName = Tracer.class.getName() + "@" + name; LOGGER.info("Initialize Tracer " + traceLoggerName); - this.traceLog = Logger.getLogger(traceLoggerName); + this.traceLog = LogManager.getLogger(traceLoggerName); this.categories = categories; this.registry = registry; final long traceCategory = getRegistry().get(CAT); diff --git a/hyracks-fullstack/hyracks/hyracks-util/src/test/java/org/apache/hyracks/util/trace/TraceTest.java b/hyracks-fullstack/hyracks/hyracks-util/src/test/java/org/apache/hyracks/util/trace/TraceTest.java index a6ed4c8..f842f3e 100644 --- a/hyracks-fullstack/hyracks/hyracks-util/src/test/java/org/apache/hyracks/util/trace/TraceTest.java +++ b/hyracks-fullstack/hyracks/hyracks-util/src/test/java/org/apache/hyracks/util/trace/TraceTest.java @@ -18,14 +18,10 @@ */ package org.apache.hyracks.util.trace; -import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.io.OutputStream; -import java.util.logging.Formatter; -import java.util.logging.LogRecord; -import java.util.logging.Logger; -import java.util.logging.StreamHandler; +import java.util.List; +import org.apache.hyracks.util.Log4j2Monitor; import org.junit.Assert; import org.junit.Test; @@ -36,18 +32,6 @@ private final ObjectMapper mapper = new ObjectMapper(); private final String name = "test"; - - private StreamHandler redirectTraceLog(OutputStream os) throws IOException { - final Logger logger = Logger.getLogger(Tracer.class.getName() + "@" + name); - final StreamHandler handler = new StreamHandler(os, new Formatter() { - @Override - public String format(LogRecord record) { - return record.getMessage() + "\n"; - } - }); - logger.addHandler(handler); - return handler; - } public JsonNode validate(String line) throws IOException { final JsonNode traceRecord = mapper.readTree(line); @@ -68,9 +52,6 @@ @Test public void testInstant() throws IOException { - final ByteArrayOutputStream os = new ByteArrayOutputStream(); - final StreamHandler handler = redirectTraceLog(os); - // test with initial categories TraceCategoryRegistry registry = new TraceCategoryRegistry(); @@ -79,13 +60,12 @@ long cat3 = registry.get("CAT3"); ITracer tracer = new Tracer(name, new String[] { "CAT1", "CAT2" }, registry); + Log4j2Monitor.start(); tracer.instant("test1", cat1, ITracer.Scope.p, null); tracer.instant("test2", cat2, ITracer.Scope.p, null); tracer.instant("test3", cat3, ITracer.Scope.p, null); - handler.flush(); - - String[] lines = os.toString().split("\n"); + List<String> lines = Log4j2Monitor.getLogs(); for (String line : lines) { final JsonNode traceRecord = validate(line); Assert.assertEquals("i", traceRecord.get("ph").asText()); @@ -93,17 +73,14 @@ } // test with modified categories - tracer.setCategories("CAT1", "CAT3"); - os.reset(); + Log4j2Monitor.reset(); tracer.instant("test1", cat1, ITracer.Scope.p, null); tracer.instant("test2", cat2, ITracer.Scope.p, null); tracer.instant("test3", cat3, ITracer.Scope.p, null); - handler.flush(); - - lines = os.toString().split("\n"); + lines = Log4j2Monitor.getLogs(); for (String line : lines) { final JsonNode traceRecord = validate(line); Assert.assertEquals("i", traceRecord.get("ph").asText()); -- To view, visit https://asterix-gerrit.ics.uci.edu/2254 To unsubscribe, visit https://asterix-gerrit.ics.uci.edu/settings Gerrit-MessageType: merged Gerrit-Change-Id: I894348b09a862693ae31de7c2f4768877a5297db Gerrit-PatchSet: 3 Gerrit-Project: asterixdb Gerrit-Branch: master Gerrit-Owner: Murtadha Hubail <[email protected]> Gerrit-Reviewer: Anon. E. Moose #1000171 Gerrit-Reviewer: Jenkins <[email protected]> Gerrit-Reviewer: Michael Blow <[email protected]> Gerrit-Reviewer: Murtadha Hubail <[email protected]> Gerrit-Reviewer: Till Westmann <[email protected]>
