[GitHub] zookeeper issue #148: ZOOKEEPER-2659 Log4j2 migration
Github user mikaelstaldal commented on the issue: https://github.com/apache/zookeeper/pull/148 I would say that it is not proper to refer to Log4j 2.x as "Log4J2". You should refer to it as "Log4j 2.x" or "Log4j 2". --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] zookeeper pull request #148: ZOOKEEPER-2659 Log4j 2 migration
Github user mikaelstaldal commented on a diff in the pull request: https://github.com/apache/zookeeper/pull/148#discussion_r96145959 --- Diff: src/java/test/org/apache/zookeeper/server/quorum/QuorumPeerMainTest.java --- @@ -413,13 +418,18 @@ public void testBadPeerAddressInQuorum() throws Exception { ClientBase.setupTestEnv(); // setup the logger to capture all logs +LoggerContext loggerContext = (LoggerContext) LogManager.getContext(false); +Configuration logConfig = loggerContext.getConfiguration(); + Layout layout = -Logger.getRootLogger().getAppender("CONSOLE").getLayout(); + logConfig.getRootLogger().getAppenders().get("STDOUT").getLayout(); +String appenderName = "quorumAppender"; ByteArrayOutputStream os = new ByteArrayOutputStream(); -WriterAppender appender = new WriterAppender(layout, os); -appender.setThreshold(Level.WARN); -Logger qlogger = Logger.getLogger("org.apache.zookeeper.server.quorum"); -qlogger.addAppender(appender); +WriterAppender appender = WriterAppender.createAppender((StringLayout)layout, null, new OutputStreamWriter(os), appenderName, false, true); --- End diff -- It's probably a good idea to use the builder to create the appender: ``` WriterAppender.newBuilder().setLayout((StringLayout)layout).setTarget(new OutputStreamWriter(os)).setName(appenderName).build(); ``` --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] zookeeper pull request #148: ZOOKEEPER-2659 Log4j 2 migration
Github user mikaelstaldal commented on a diff in the pull request: https://github.com/apache/zookeeper/pull/148#discussion_r96145992 --- Diff: src/java/test/org/apache/zookeeper/server/quorum/QuorumPeerMainTest.java --- @@ -615,14 +631,18 @@ public void testQuorumDefaults() throws Exception { ClientBase.setupTestEnv(); // setup the logger to capture all logs +LoggerContext loggerContext = (LoggerContext) LogManager.getContext(false); +Configuration logConfig = loggerContext.getConfiguration(); + Layout layout = -Logger.getRootLogger().getAppender("CONSOLE").getLayout(); + logConfig.getRootLogger().getAppenders().get("STDOUT").getLayout(); +String appenderName = "quorumAppender"; ByteArrayOutputStream os = new ByteArrayOutputStream(); -WriterAppender appender = new WriterAppender(layout, os); -appender.setImmediateFlush(true); -appender.setThreshold(Level.INFO); -Logger zlogger = Logger.getLogger("org.apache.zookeeper"); -zlogger.addAppender(appender); +WriterAppender appender = WriterAppender.createAppender((StringLayout)layout, null, new OutputStreamWriter(os), appenderName, false, true); --- End diff -- It's probably a good idea to use the builder to create the appender (see above). --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] zookeeper pull request #148: ZOOKEEPER-2659 Log4j 2 migration
Github user mikaelstaldal commented on a diff in the pull request: https://github.com/apache/zookeeper/pull/148#discussion_r96145970 --- Diff: src/java/test/org/apache/zookeeper/server/quorum/QuorumPeerMainTest.java --- @@ -470,16 +481,20 @@ public void testBadPeerAddressInQuorum() throws Exception { @Test public void testInconsistentPeerType() throws Exception { ClientBase.setupTestEnv(); - -// setup the logger to capture all logs + +LoggerContext loggerContext = (LoggerContext) LogManager.getContext(false); +Configuration logConfig = loggerContext.getConfiguration(); + Layout layout = -Logger.getRootLogger().getAppender("CONSOLE").getLayout(); + logConfig.getRootLogger().getAppenders().get("STDOUT").getLayout(); +String appenderName = "quorumAppender"; ByteArrayOutputStream os = new ByteArrayOutputStream(); -WriterAppender appender = new WriterAppender(layout, os); -appender.setThreshold(Level.INFO); -Logger qlogger = Logger.getLogger("org.apache.zookeeper.server.quorum"); -qlogger.addAppender(appender); - +WriterAppender appender = WriterAppender.createAppender((StringLayout)layout, null, new OutputStreamWriter(os), appenderName, false, true); --- End diff -- It's probably a good idea to use the builder to create the appender (see above). --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] zookeeper pull request #148: ZOOKEEPER-2659 Log4j 2 migration
Github user mikaelstaldal commented on a diff in the pull request: https://github.com/apache/zookeeper/pull/148#discussion_r96146002 --- Diff: src/java/test/org/apache/zookeeper/test/ReadOnlyModeTest.java --- @@ -251,14 +257,19 @@ public void testSessionEstablishment() throws Exception { @Test(timeout = 9) public void testSeekForRwServer() throws Exception { // setup the logger to capture all logs -Layout layout = Logger.getRootLogger().getAppender("CONSOLE") -.getLayout(); +LoggerContext loggerContext = (LoggerContext) LogManager.getContext(false); +Configuration logConfig = loggerContext.getConfiguration(); + +Layout layout = + logConfig.getRootLogger().getAppenders().get("STDOUT").getLayout(); +String appenderName = "zkAppender"; ByteArrayOutputStream os = new ByteArrayOutputStream(); -WriterAppender appender = new WriterAppender(layout, os); -appender.setImmediateFlush(true); -appender.setThreshold(Level.INFO); -Logger zlogger = Logger.getLogger("org.apache.zookeeper"); -zlogger.addAppender(appender); +WriterAppender appender = WriterAppender.createAppender((StringLayout)layout, null, new OutputStreamWriter(os), appenderName, false, true); --- End diff -- It's probably a good idea to use the builder to create the appender (see above). --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---