Skip to content

Commit ce148a7

Browse files
rahulrane50iamgd67
andauthored
ZOOKEEPER-4465: zooinspector logback pattern config add escape for '(' and ')' (#109)
Cherry picked #PR1814 Co-authored-by: 67 <[email protected]>
1 parent 2e8a9b5 commit ce148a7

File tree

2 files changed

+49
-1
lines changed
  • zookeeper-contrib/zookeeper-contrib-zooinspector/src

2 files changed

+49
-1
lines changed

zookeeper-contrib/zookeeper-contrib-zooinspector/src/main/resources/logback.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<configuration>
2323
<appender name="stdout" class="ch.qos.logback.core.ConsoleAppender">
2424
<encoder>
25-
<pattern>%5p [%t] (%F:%L) - %m%n</pattern>
25+
<pattern>%5p [%t] \(%F:%L\) - %m%n</pattern>
2626
</encoder>
2727
</appender>
2828
<root level="INFO">
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package org.apache.zookeeper.inspector;
19+
20+
import org.junit.Assert;
21+
import org.junit.Test;
22+
import org.slf4j.Logger;
23+
import org.slf4j.LoggerFactory;
24+
25+
import java.io.ByteArrayOutputStream;
26+
import java.io.PrintStream;
27+
import java.nio.charset.StandardCharsets;
28+
29+
public class LoggerTest {
30+
Logger LOG = LoggerFactory.getLogger(LoggerTest.class);
31+
String testMessage = "a test message";
32+
33+
@Test
34+
public void testLogStdOutConfig() {
35+
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
36+
PrintStream realStdOut = System.out;
37+
System.setOut(new PrintStream(byteArrayOutputStream));
38+
LOG.info(testMessage);
39+
System.setOut(realStdOut);
40+
41+
//log to stdout for debug
42+
LOG.info(testMessage);
43+
String bufferMessage = new String(byteArrayOutputStream.toByteArray(), StandardCharsets.UTF_8);
44+
LOG.info(bufferMessage);
45+
46+
Assert.assertTrue(bufferMessage.contains(testMessage));
47+
}
48+
}

0 commit comments

Comments
 (0)