Repository: logging-log4j2 Updated Branches: refs/heads/master b40793c2f -> 1167a72d7
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1167a72d/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerBufferedReaderTest.java ---------------------------------------------------------------------- diff --git a/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerBufferedReaderTest.java b/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerBufferedReaderTest.java new file mode 100644 index 0000000..ebbe2d3 --- /dev/null +++ b/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerBufferedReaderTest.java @@ -0,0 +1,41 @@ +/* + * 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.logging.log4j.streams; + +import static org.junit.Assert.assertEquals; + +import java.io.BufferedReader; +import java.io.Reader; + +import org.junit.Test; + +public class LoggerBufferedReaderTest extends LoggerReaderTest { + private BufferedReader reader; + + @Override + protected Reader createReader() { + return this.reader = new LoggerBufferedReader(wrapped, getLogger(), LEVEL); + } + + @Test + public void testReadLine() throws Exception { + assertEquals("first line", FIRST, reader.readLine()); + assertMessages(FIRST); + assertEquals("second line", LAST, reader.readLine()); + assertMessages(FIRST, LAST); + } +} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1167a72d/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerInputStreamCallerInfoTest.java ---------------------------------------------------------------------- diff --git a/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerInputStreamCallerInfoTest.java b/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerInputStreamCallerInfoTest.java new file mode 100644 index 0000000..5942217 --- /dev/null +++ b/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerInputStreamCallerInfoTest.java @@ -0,0 +1,54 @@ +/* + * 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.logging.log4j.streams; + +import java.io.ByteArrayInputStream; +import java.io.InputStream; + +import org.apache.logging.log4j.Level; +import org.junit.Before; +import org.junit.Test; + +public class LoggerInputStreamCallerInfoTest extends LoggerStreamsCallerInfoTesting { + + private LoggerInputStream logIn; + + @Before + public void setupStreams() { + final InputStream srcInputStream = new ByteArrayInputStream("a\nb\nc\nd".getBytes()); + logIn = new LoggerInputStream(srcInputStream, getLogger(), Level.WARN); + } + + @Test + public void read() throws Exception { + logIn.read(); + assertMessages("before read int size", 0, "read"); + logIn.read(); + assertMessages("after read int size", 1, "read"); + + logIn.read(new byte[2]); + assertMessages("after read bytes size", 2, "read"); + + logIn.read(new byte[2], 0, 2); + assertMessages("after read bytes offset size", 3, "read"); + + logIn.read(); + assertMessages("before close size", 3, "read"); + logIn.close(); + assertMessages("after close size", 4, "read"); + } +} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1167a72d/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerInputStreamTest.java ---------------------------------------------------------------------- diff --git a/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerInputStreamTest.java b/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerInputStreamTest.java new file mode 100644 index 0000000..919449b --- /dev/null +++ b/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerInputStreamTest.java @@ -0,0 +1,127 @@ +/* + * 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.logging.log4j.streams; + +import static org.junit.Assert.assertEquals; + +import java.io.BufferedInputStream; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; + +import org.junit.Before; +import org.junit.Test; + +public class LoggerInputStreamTest extends StreamTesting { + protected ByteArrayInputStream wrapped; + protected ByteArrayOutputStream read; + protected InputStream in; + + @Before + public void createStream() { + wrapped = new ByteArrayInputStream((FIRST + "\r\n" + LAST).getBytes()); + read = new ByteArrayOutputStream(); + in = createInputStream(); + } + + protected InputStream createInputStream() { + return new LoggerInputStream(wrapped, getLogger(), LEVEL); + } + + @Test + public void testRead_int() throws Exception { + for (int i = 0; i < FIRST.length(); i++) { + read.write(in.read()); + } + if (!(in instanceof BufferedInputStream)) { + assertMessages(); + } + assertEquals("carriage return", '\r', in.read()); + if (!(in instanceof BufferedInputStream)) { + assertMessages(); + } + assertEquals("newline", '\n', in.read()); + assertMessages(FIRST); + } + + @Test + public void testRead_ByteArray() throws Exception { + final byte[] bytes = new byte[FIRST.length()]; + assertEquals("len", bytes.length, in.read(bytes)); + if (!(in instanceof BufferedInputStream)) { + assertMessages(); + } + in.read(bytes); + assertMessages(FIRST); + } + + @Test + public void testRead_ByteArray_Offset_Length() throws Exception { + final byte[] bytes = new byte[FIRST.length() * 2]; + assertEquals("len", FIRST.length(), in.read(bytes, 0, FIRST.length())); + if (!(in instanceof BufferedInputStream)) { + assertMessages(); + } + in.read(bytes); + assertMessages(FIRST); + } + + @Test + public void testRead_IgnoresWindowsNewline() throws IOException { + final byte[] bytes = new byte[1024]; + int len = in.read(bytes); + read.write(bytes, 0, len); + assertMessages(FIRST); + assertEquals(FIRST + "\r\n" + LAST, read.toString()); + in.close(); + assertMessages(FIRST, LAST); + } + + @Test + public void testRead_MultipleLines() throws IOException { + wrapped = new ByteArrayInputStream((FIRST + "\n" + LAST + '\n').getBytes()); + in = new LoggerInputStream(wrapped, getLogger(), LEVEL); + + final byte[] bytes = new byte[1024]; + int len = in.read(bytes); + read.write(bytes, 0, len); + assertMessages(FIRST, LAST); + assertEquals(FIRST + '\n' + LAST + '\n', read.toString()); + } + + @Test + public void testClose_NoRemainingData() throws IOException { + wrapped = new ByteArrayInputStream((FIRST + '\n').getBytes()); + in = new LoggerInputStream(wrapped, getLogger(), LEVEL); + + final byte[] bytes = new byte[1024]; + in.read(bytes); + assertMessages(FIRST); + in.close(); + assertMessages(FIRST); + } + + @Test + public void testClose_HasRemainingData() throws IOException { + final byte[] bytes = new byte[1024]; + in.read(bytes); + assertMessages(FIRST); + in.close(); + assertMessages(FIRST, LAST); + } +} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1167a72d/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerOutputStreamCallerInfoTest.java ---------------------------------------------------------------------- diff --git a/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerOutputStreamCallerInfoTest.java b/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerOutputStreamCallerInfoTest.java new file mode 100644 index 0000000..662aae4 --- /dev/null +++ b/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerOutputStreamCallerInfoTest.java @@ -0,0 +1,50 @@ +/* + * 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.logging.log4j.streams; + +import org.apache.logging.log4j.Level; +import org.junit.Before; +import org.junit.Test; + +public class LoggerOutputStreamCallerInfoTest extends LoggerStreamsCallerInfoTesting { + + private LoggerOutputStream logOut; + + @Before + public void setupStreams() { + logOut = new LoggerOutputStream(getLogger(), Level.WARN); + } + + @Test + public void write() throws Exception { + logOut.write('a'); + assertMessages("before write int", 0, "write"); + logOut.write('\n'); + assertMessages("after write int", 1, "write"); + + logOut.write("b\n".getBytes()); + assertMessages("after write byte array", 2, "write"); + + logOut.write("c\n".getBytes(), 0, 2); + assertMessages("after write byte array offset size", 3, "write"); + + logOut.write('d'); + assertMessages("before close size", 3, "write"); + logOut.close(); + assertMessages("after close size", 4, "write"); + } +} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1167a72d/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerOutputStreamTest.java ---------------------------------------------------------------------- diff --git a/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerOutputStreamTest.java b/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerOutputStreamTest.java new file mode 100644 index 0000000..94c4c55 --- /dev/null +++ b/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerOutputStreamTest.java @@ -0,0 +1,125 @@ +/* + * 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.logging.log4j.streams; + +import static org.easymock.EasyMock.replay; +import static org.easymock.EasyMock.verify; +import static org.junit.Assert.assertEquals; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.OutputStream; + +import org.apache.logging.log4j.Level; +import org.easymock.EasyMock; +import org.junit.Before; +import org.junit.Test; + +public class LoggerOutputStreamTest extends StreamTesting { + protected ByteArrayOutputStream wrapped; + protected OutputStream out; + + @Before + public void createStream() { + wrapped = new ByteArrayOutputStream(); + out = createOutputStream(); + } + + protected OutputStream createOutputStream() { + return new LoggerOutputStream(wrapped, getLogger(), Level.ERROR); + } + + @Test + public void testWrite_Int() throws Exception { + for (byte b : "int".getBytes()) { + out.write(b); + assertMessages(); + } + out.write('\n'); + assertMessages("int"); + assertEquals("int" + '\n', wrapped.toString()); + } + + @Test + public void testWrite_ByteArray() throws Exception { + final byte[] bytes = "byte[]".getBytes(); + out.write(bytes); + assertMessages(); + out.write('\n'); + assertMessages("byte[]"); + assertEquals("byte[]\n", wrapped.toString()); + } + + @Test + public void testWrite_ByteArray_Offset_Length() throws Exception { + final byte[] bytes = "byte[]".getBytes(); + int middle = bytes.length/2; + int length = bytes.length - middle; + final String right = new String(bytes, middle, length); + out.write(bytes, middle, length); + assertMessages(); + out.write('\n'); + assertMessages(right); + assertEquals("byte[]".substring(middle, bytes.length) + '\n', wrapped.toString()); + } + + @Test + public void testWrite_IgnoresWindowsNewline() throws IOException { + out.write(FIRST.getBytes()); + out.write("\r\n".getBytes()); + out.write(LAST.getBytes()); + out.close(); + assertMessages(FIRST, LAST); + assertEquals(FIRST + "\r\n" + LAST, wrapped.toString()); + } + + @Test + public void testWrite_MultipleLines() throws IOException { + out.write((FIRST + '\n' + LAST + '\n').getBytes()); + assertMessages(FIRST, LAST); + assertEquals(FIRST + '\n' + LAST + '\n', wrapped.toString()); + } + + @Test + public void testFlush() throws IOException { + final OutputStream out = EasyMock.createMock("out", OutputStream.class); + out.flush(); // expect the flush to come through to the mocked OutputStream + out.close(); + replay(out); + + final LoggerOutputStream los = new LoggerOutputStream(out, getLogger(), LEVEL); + los.flush(); + los.close(); + verify(out); + } + + @Test + public void testClose_NoRemainingData() throws IOException { + out.close(); + assertMessages(); + assertEquals("", wrapped.toString()); + } + + @Test + public void testClose_HasRemainingData() throws IOException { + out.write(FIRST.getBytes()); + assertMessages(); + out.close(); + assertMessages(FIRST); + assertEquals(FIRST, wrapped.toString()); + } +} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1167a72d/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerPrintStreamCallerInfoTest.java ---------------------------------------------------------------------- diff --git a/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerPrintStreamCallerInfoTest.java b/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerPrintStreamCallerInfoTest.java new file mode 100644 index 0000000..ebd57cf --- /dev/null +++ b/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerPrintStreamCallerInfoTest.java @@ -0,0 +1,145 @@ +/* + * 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.logging.log4j.streams; + +import java.util.Locale; + +import org.apache.logging.log4j.Level; +import org.junit.Before; +import org.junit.Test; + +public class LoggerPrintStreamCallerInfoTest extends LoggerStreamsCallerInfoTesting { + + private LoggerPrintStream logOut; + + @Before + public void setupStreams() { + logOut = new LoggerPrintStream(getLogger(), Level.WARN); + } + + @Test + public void write_int() throws Exception { + logOut.write('a'); + assertMessages("write int", 0, "write_int"); + logOut.write('\n'); + assertMessages("write newline", 1, "write_int"); + } + + @Test + public void write_bytes() throws Exception { + logOut.write("b\n".getBytes()); + assertMessages("write", 1, "write_bytes"); + } + + @Test + public void write_bytes_offset() throws Exception { + logOut.write("c\n".getBytes(), 0, 2); + assertMessages("write", 1, "write_bytes_offset"); + } + + @Test + public void print_boolean() throws Exception { + logOut.print(true); + assertMessages("print", 0, "print_boolean"); + logOut.println(true); + assertMessages("println", 1, "print_boolean"); + } + + @Test + public void print_char() throws Exception { + logOut.print('a'); + assertMessages("print", 0, "print_char"); + logOut.println('b'); + assertMessages("println", 1, "print_char"); + } + + @Test + public void print_chararray() throws Exception { + logOut.print("a".toCharArray()); + assertMessages("print", 0, "print_chararray"); + logOut.println("b".toCharArray()); + assertMessages("println", 1, "print_chararray"); + } + + @Test + public void print_double() throws Exception { + logOut.print(1D); + assertMessages("print", 0, "print_double"); + logOut.println(2D); + assertMessages("println", 1, "print_double"); + } + + @Test + public void print_float() throws Exception { + logOut.print(1f); + assertMessages("print", 0, "print_float"); + logOut.println(2f); + assertMessages("println", 1, "print_float"); + } + + @Test + public void print_int() throws Exception { + logOut.print(1); + assertMessages("print", 0, "print_int"); + logOut.println(2); + assertMessages("println", 1, "print_int"); + } + + @Test + public void print_long() throws Exception { + logOut.print(1L); + assertMessages("print", 0, "print_long"); + logOut.println(2L); + assertMessages("println", 1, "print_long"); + } + + @Test + public void print_object() throws Exception { + logOut.print((Object) 'a'); + assertMessages("print", 0, "print_object"); + logOut.println((Object) 'b'); + assertMessages("println", 1, "print_object"); + } + + @Test + public void print_string() throws Exception { + logOut.print("a"); + assertMessages("print", 0, "print_string"); + logOut.println("b"); + assertMessages("println", 1, "print_string"); + } + + @Test + public void print_printf() throws Exception { + logOut.printf("a\n"); + assertMessages("println", 1, "print_printf"); + } + + @Test + public void print_printf_locale() throws Exception { + logOut.printf(Locale.getDefault(), "a\n"); + assertMessages("println", 1, "print_printf_locale"); + } + + @Test + public void close() throws Exception { + logOut.print("a\nb"); + assertMessages("before close size", 1, "close"); + logOut.close(); + assertMessages("after close size", 2, "close"); + } +} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1167a72d/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerPrintStreamTest.java ---------------------------------------------------------------------- diff --git a/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerPrintStreamTest.java b/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerPrintStreamTest.java new file mode 100644 index 0000000..9cae0dc --- /dev/null +++ b/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerPrintStreamTest.java @@ -0,0 +1,116 @@ +/* + * 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.logging.log4j.streams; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertSame; + +import java.io.OutputStream; + +import org.junit.Test; + +public class LoggerPrintStreamTest extends LoggerOutputStreamTest { + private LoggerPrintStream print; + + @Override + protected OutputStream createOutputStream() { + return this.print = new LoggerPrintStream(wrapped, getLogger(), LEVEL); + } + + @Test + public void testPrint_boolean() throws Exception { + print.print(true); + assertMessages(); + print.println(); + assertMessages("true"); + assertEquals("true" + NEWLINE, wrapped.toString()); + } + + @Test + public void testPrint_char() throws Exception { + for (char c : FIRST.toCharArray()) { + print.print(c); + assertMessages(); + } + print.println(); + assertMessages(FIRST); + assertEquals(FIRST + NEWLINE, wrapped.toString()); + } + + @Test + public void testPrint_int() throws Exception { + print.print(12); + assertMessages(); + print.println(); + assertMessages("12"); + assertEquals("12" + NEWLINE, wrapped.toString()); + } + + @Test + public void testPrint_long() throws Exception { + print.print(12L); + assertMessages(); + print.println(); + assertMessages("12"); + assertEquals("12" + NEWLINE, wrapped.toString()); + } + + @Test + public void testPrint_CharacterArray() throws Exception { + print.print(FIRST.toCharArray()); + assertMessages(); + print.println(); + assertMessages(FIRST); + assertEquals(FIRST + NEWLINE, wrapped.toString()); + } + + @Test + public void testPrint_String() throws Exception { + print.print(FIRST); + assertMessages(); + print.println(); + assertMessages(FIRST); + assertEquals(FIRST + NEWLINE, wrapped.toString()); + } + + @Test + public void testPrint_Object() throws Exception { + print.print((Object) FIRST); + assertMessages(); + print.println(); + assertMessages(FIRST); + assertEquals(FIRST + NEWLINE, wrapped.toString()); + } + + @Test + public void testPrintf() throws Exception { + assertSame(print, print.printf("<<<%s>>>", FIRST)); + assertMessages(); + print.println(); + assertMessages("<<<" + FIRST + ">>>"); + assertEquals("<<<" + FIRST + ">>>" + NEWLINE, wrapped.toString()); + } + + @Test + public void testFormat() throws Exception { + assertSame(print, print.format("[%s]", FIRST)); + assertMessages(); + print.println(); + assertMessages("[" + FIRST + "]"); + assertEquals("[" + FIRST + "]" + NEWLINE, wrapped.toString()); + } +} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1167a72d/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerPrintWriterCallerInfoTest.java ---------------------------------------------------------------------- diff --git a/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerPrintWriterCallerInfoTest.java b/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerPrintWriterCallerInfoTest.java new file mode 100644 index 0000000..2b825ec --- /dev/null +++ b/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerPrintWriterCallerInfoTest.java @@ -0,0 +1,145 @@ +/* + * 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.logging.log4j.streams; + +import java.util.Locale; + +import org.apache.logging.log4j.Level; +import org.junit.Before; +import org.junit.Test; + +public class LoggerPrintWriterCallerInfoTest extends LoggerStreamsCallerInfoTesting { + + private LoggerPrintWriter logOut; + + @Before + public void setupStreams() { + logOut = new LoggerPrintWriter(getLogger(), Level.WARN); + } + + @Test + public void write_int() throws Exception { + logOut.write('a'); + assertMessages("write int", 0, "write_int"); + logOut.write('\n'); + assertMessages("write newline", 1, "write_int"); + } + + @Test + public void write_bytes() throws Exception { + logOut.write("b\n".toCharArray()); + assertMessages("write", 1, "write_bytes"); + } + + @Test + public void write_bytes_offset() throws Exception { + logOut.write("c\n".toCharArray(), 0, 2); + assertMessages("write", 1, "write_bytes_offset"); + } + + @Test + public void print_boolean() throws Exception { + logOut.print(true); + assertMessages("print", 0, "print_boolean"); + logOut.println(true); + assertMessages("println", 1, "print_boolean"); + } + + @Test + public void print_char() throws Exception { + logOut.print('a'); + assertMessages("print", 0, "print_char"); + logOut.println('b'); + assertMessages("println", 1, "print_char"); + } + + @Test + public void print_chararray() throws Exception { + logOut.print("a".toCharArray()); + assertMessages("print", 0, "print_chararray"); + logOut.println("b".toCharArray()); + assertMessages("println", 1, "print_chararray"); + } + + @Test + public void print_double() throws Exception { + logOut.print(1D); + assertMessages("print", 0, "print_double"); + logOut.println(2D); + assertMessages("println", 1, "print_double"); + } + + @Test + public void print_float() throws Exception { + logOut.print(1f); + assertMessages("print", 0, "print_float"); + logOut.println(2f); + assertMessages("println", 1, "print_float"); + } + + @Test + public void print_int() throws Exception { + logOut.print(1); + assertMessages("print", 0, "print_int"); + logOut.println(2); + assertMessages("println", 1, "print_int"); + } + + @Test + public void print_long() throws Exception { + logOut.print(1L); + assertMessages("print", 0, "print_long"); + logOut.println(2L); + assertMessages("println", 1, "print_long"); + } + + @Test + public void print_object() throws Exception { + logOut.print((Object) 'a'); + assertMessages("print", 0, "print_object"); + logOut.println((Object) 'b'); + assertMessages("println", 1, "print_object"); + } + + @Test + public void print_string() throws Exception { + logOut.print("a"); + assertMessages("print", 0, "print_string"); + logOut.println("b"); + assertMessages("println", 1, "print_string"); + } + + @Test + public void print_printf() throws Exception { + logOut.printf("a\n"); + assertMessages("println", 1, "print_printf"); + } + + @Test + public void print_printf_locale() throws Exception { + logOut.printf(Locale.getDefault(), "a\n"); + assertMessages("println", 1, "print_printf_locale"); + } + + @Test + public void close() throws Exception { + logOut.print("a\nb"); + assertMessages("before close size", 1, "close"); + logOut.close(); + assertMessages("after close size", 2, "close"); + } +} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1167a72d/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerPrintWriterTest.java ---------------------------------------------------------------------- diff --git a/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerPrintWriterTest.java b/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerPrintWriterTest.java new file mode 100644 index 0000000..e8d2996 --- /dev/null +++ b/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerPrintWriterTest.java @@ -0,0 +1,118 @@ +/* + * 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.logging.log4j.streams; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertSame; + +import java.io.PrintWriter; +import java.io.Writer; + +import org.junit.Test; + +public class LoggerPrintWriterTest extends LoggerWriterTest { + private PrintWriter print; + + @Override + protected Writer createWriter() { + this.print = new LoggerPrintWriter(wrapped, getLogger(), LEVEL); + return this.print; + } + + @Test + public void testPrint_boolean() throws Exception { + print.print(true); + assertMessages(); + print.println(); + assertMessages("true"); + assertEquals("true" + NEWLINE, wrapped.toString()); + } + + @Test + public void testPrint_char() throws Exception { + for (char c : FIRST.toCharArray()) { + print.print(c); + assertMessages(); + } + print.println(); + assertMessages(FIRST); + assertEquals(FIRST + NEWLINE, wrapped.toString()); + } + + @Test + public void testPrint_int() throws Exception { + print.print(12); + assertMessages(); + print.println(); + assertMessages("12"); + assertEquals("12" + NEWLINE, wrapped.toString()); + } + + @Test + public void testPrint_long() throws Exception { + print.print(12L); + assertMessages(); + print.println(); + assertMessages("12"); + assertEquals("12" + NEWLINE, wrapped.toString()); + } + + @Test + public void testPrint_CharacterArray() throws Exception { + print.print(FIRST.toCharArray()); + assertMessages(); + print.println(); + assertMessages(FIRST); + assertEquals(FIRST + NEWLINE, wrapped.toString()); + } + + @Test + public void testPrint_String() throws Exception { + print.print(FIRST); + assertMessages(); + print.println(); + assertMessages(FIRST); + assertEquals(FIRST + NEWLINE, wrapped.toString()); + } + + @Test + public void testPrint_Object() throws Exception { + print.print((Object) FIRST); + assertMessages(); + print.println(); + assertMessages(FIRST); + assertEquals(FIRST + NEWLINE, wrapped.toString()); + } + + @Test + public void testPrintf() throws Exception { + assertSame(print, print.printf("<<<%s>>>", FIRST)); + assertMessages(); + print.println(); + assertMessages("<<<" + FIRST + ">>>"); + assertEquals("<<<" + FIRST + ">>>" + NEWLINE, wrapped.toString()); + } + + @Test + public void testFormat() throws Exception { + assertSame(print, print.format("[%s]", FIRST)); + assertMessages(); + print.println(); + assertMessages("[" + FIRST + "]"); + assertEquals("[" + FIRST + "]" + NEWLINE, wrapped.toString()); + } +} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1167a72d/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerReaderCallerInfoTest.java ---------------------------------------------------------------------- diff --git a/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerReaderCallerInfoTest.java b/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerReaderCallerInfoTest.java new file mode 100644 index 0000000..cce13f4 --- /dev/null +++ b/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerReaderCallerInfoTest.java @@ -0,0 +1,57 @@ +/* + * 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.logging.log4j.streams; + +import java.io.Reader; +import java.io.StringReader; +import java.nio.CharBuffer; + +import org.junit.Before; +import org.junit.Test; + +public class LoggerReaderCallerInfoTest extends LoggerStreamsCallerInfoTesting { + + LoggerReader logReader; + + @Before + public void setupReader() { + final Reader srcReader = new StringReader("a\nb\nc\nd\ne"); + logReader = new LoggerReader(srcReader, getLogger(), LEVEL); + } + + @Test + public void read() throws Exception { + logReader.read(); + assertMessages("before read int size", 0, "read"); + logReader.read(); + assertMessages("after read int size", 1, "read"); + + logReader.read(new char[2]); + assertMessages("after read bytes size", 2, "read"); + + logReader.read(new char[2], 0, 2); + assertMessages("after read bytes offset size", 3, "read"); + + logReader.read(CharBuffer.allocate(2)); + assertMessages("after read charBuffer size", 4, "read"); + + logReader.read(); + assertMessages("before close size", 4, "read"); + logReader.close(); + assertMessages("after close size", 5, "read"); + } +} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1167a72d/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerReaderTest.java ---------------------------------------------------------------------- diff --git a/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerReaderTest.java b/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerReaderTest.java new file mode 100644 index 0000000..f94c96c --- /dev/null +++ b/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerReaderTest.java @@ -0,0 +1,141 @@ +/* + * 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.logging.log4j.streams; + +import static org.junit.Assert.assertEquals; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.Reader; +import java.io.StringReader; +import java.io.StringWriter; +import java.nio.CharBuffer; + +import org.junit.Before; +import org.junit.Test; + +public class LoggerReaderTest extends StreamTesting { + protected StringReader wrapped; + protected StringWriter read; + protected Reader reader; + + @Before + public void createStream() { + wrapped = new StringReader(FIRST + "\r\n" + LAST); + read = new StringWriter(); + reader = createReader(); + } + + protected Reader createReader() { + return new LoggerReader(wrapped, getLogger(), LEVEL); + } + + @Test + public void testRead_int() throws Exception { + for (int i = 0; i < FIRST.length(); i++) { + read.write(reader.read()); + } + if (!(reader instanceof BufferedReader)) { + assertMessages(); + } + assertEquals("carriage return", '\r', reader.read()); + if (!(reader instanceof BufferedReader)) { + assertMessages(); + } + assertEquals("newline", '\n', reader.read()); + assertMessages(FIRST); + } + + @Test + public void testRead_CharArray() throws Exception { + final char[] chars = new char[FIRST.length()]; + assertEquals("len", FIRST.length(), reader.read(chars)); + if (!(reader instanceof BufferedReader)) { + assertMessages(); + } + reader.read(chars); + assertMessages(FIRST); + } + + @Test + public void testRead_CharArray_Offset_Length() throws Exception { + final char[] chars = new char[1024]; + assertEquals("len", FIRST.length(), reader.read(chars, 0, FIRST.length())); + if (!(reader instanceof BufferedReader)) { + assertMessages(); + } + reader.read(chars); + reader.close(); + assertMessages(FIRST, LAST); + } + + @Test + public void testRead_CharBuffer() throws Exception { + final CharBuffer chars = CharBuffer.allocate(1024); + assertEquals("len", FIRST.length() + LAST.length() + 2, reader.read(chars)); + reader.close(); + assertMessages(FIRST, LAST); + } + + @Test + public void testRead_IgnoresWindowsNewline() throws IOException { + final char[] chars = new char[1024]; + int len = reader.read(chars); + read.write(chars, 0, len); + if (!(reader instanceof BufferedReader)) { + assertMessages(FIRST); + } + assertEquals(FIRST + "\r\n" + LAST, read.toString()); + reader.close(); + assertMessages(FIRST, LAST); + } + + @Test + public void testRead_MultipleLines() throws IOException { + wrapped = new StringReader(FIRST + "\n" + LAST + '\n'); + reader = createReader(); + + final char[] chars = new char[1024]; + int len = reader.read(chars); + read.write(chars, 0, len); + assertMessages(FIRST, LAST); + assertEquals(FIRST + '\n' + LAST + '\n', read.toString()); + } + + @Test + public void testClose_NoRemainingData() throws IOException { + wrapped = new StringReader(FIRST + '\n'); + reader = createReader(); + + final char[] chars = new char[1024]; + reader.read(chars); + assertMessages(FIRST); + reader.close(); + assertMessages(FIRST); + } + + @Test + public void testClose_HasRemainingData() throws IOException { + final char[] chars = new char[1024]; + reader.read(chars); + if (!(reader instanceof BufferedReader)) { + assertMessages(FIRST); + } + reader.close(); + assertMessages(FIRST, LAST); + } +} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1167a72d/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerStreamsCallerInfoTesting.java ---------------------------------------------------------------------- diff --git a/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerStreamsCallerInfoTesting.java b/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerStreamsCallerInfoTesting.java new file mode 100644 index 0000000..430d4b7 --- /dev/null +++ b/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerStreamsCallerInfoTesting.java @@ -0,0 +1,51 @@ +/* + * 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.logging.log4j.streams; + +import static org.junit.Assert.assertEquals; + +import org.apache.logging.log4j.Level; +import org.apache.logging.log4j.core.Logger; +import org.apache.logging.log4j.junit.InitialLoggerContext; +import org.apache.logging.log4j.test.appender.ListAppender; +import org.junit.Before; +import org.junit.ClassRule; + +public class LoggerStreamsCallerInfoTesting { + + protected final static Level LEVEL = Level.WARN; + + @ClassRule + public static InitialLoggerContext ctx = new InitialLoggerContext("log4j2-streams-calling-info.xml"); + + protected static Logger getLogger() { + return ctx.getLogger("ClassAndMethodLogger"); + } + + @Before + public void clearAppender() { + ((ListAppender) ctx.getAppender("ClassAndMethod")).clear(); + } + + public void assertMessages(final String msg, int size, String methodName) { + ListAppender appender = (ListAppender) ctx.getAppender("ClassAndMethod"); + assertEquals(msg + ".size", size, appender.getMessages().size()); + for (final String message : appender.getMessages()) { + assertEquals(msg + " has incorrect caller info", this.getClass().getName() + '.' + methodName, message); + } + } +} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1167a72d/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerWriterTest.java ---------------------------------------------------------------------- diff --git a/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerWriterTest.java b/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerWriterTest.java new file mode 100644 index 0000000..b14fdc0 --- /dev/null +++ b/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerWriterTest.java @@ -0,0 +1,124 @@ +/* + * 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.logging.log4j.streams; + +import static org.easymock.EasyMock.replay; +import static org.easymock.EasyMock.verify; +import static org.junit.Assert.assertEquals; + +import java.io.IOException; +import java.io.OutputStream; +import java.io.StringWriter; +import java.io.Writer; + +import org.easymock.EasyMock; +import org.junit.Before; +import org.junit.Test; + +public class LoggerWriterTest extends StreamTesting { + protected StringWriter wrapped; + protected Writer writer; + + @Before + public void createStream() { + wrapped = new StringWriter(); + writer = createWriter(); + } + + protected Writer createWriter() { + return new LoggerWriter(wrapped, getLogger(), LEVEL); + } + + @Test + public void testWrite_CharArray() throws Exception { + final char[] chars = FIRST.toCharArray(); + writer.write(chars); + assertMessages(); + writer.write('\n'); + assertMessages(FIRST); + assertEquals(FIRST + '\n', wrapped.toString()); + } + + @Test + public void testWrite_CharArray_Offset_Length() throws Exception { + final char[] chars = FIRST.toCharArray(); + int middle = chars.length / 2; + int length = chars.length - middle; + final String right = new String(chars, middle, length); + writer.write(chars, middle, length); + assertMessages(); + writer.write('\n'); + assertMessages(right); + assertEquals(FIRST.substring(middle, FIRST.length()) + '\n', wrapped.toString()); + } + + @Test + public void testWrite_Character() throws Exception { + for (char c : FIRST.toCharArray()) { + writer.write(c); + assertMessages(); + } + writer.write('\n'); + assertMessages(FIRST); + assertEquals(FIRST + '\n', wrapped.toString()); + } + + @Test + public void testWrite_IgnoresWindowsNewline() throws IOException { + writer.write(FIRST + "\r\n"); + writer.write(LAST); + writer.close(); + assertMessages(FIRST, LAST); + assertEquals(FIRST + "\r\n" + LAST, wrapped.toString()); + } + + @Test + public void testWrite_MultipleLines() throws IOException { + writer.write(FIRST + '\n' + LAST + '\n'); + assertMessages(FIRST, LAST); + assertEquals(FIRST + '\n' + LAST + '\n', wrapped.toString()); + } + + @Test + public void testFlush() throws IOException { + final OutputStream out = EasyMock.createMock(OutputStream.class); + out.flush(); // expect the flush to come through to the mocked OutputStream + out.close(); + replay(out); + + final LoggerOutputStream los = new LoggerOutputStream(out, getLogger(), LEVEL); + los.flush(); + los.close(); + verify(out); + } + + @Test + public void testClose_NoRemainingData() throws IOException { + writer.close(); + assertMessages(); + assertEquals("", wrapped.toString()); + } + + @Test + public void testClose_HasRemainingData() throws IOException { + writer.write(FIRST); + assertMessages(); + writer.close(); + assertMessages(FIRST); + assertEquals(FIRST, wrapped.toString()); + } +} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1167a72d/log4j-streams/src/test/java/org/apache/logging/log4j/streams/StreamTesting.java ---------------------------------------------------------------------- diff --git a/log4j-streams/src/test/java/org/apache/logging/log4j/streams/StreamTesting.java b/log4j-streams/src/test/java/org/apache/logging/log4j/streams/StreamTesting.java new file mode 100644 index 0000000..80adf20 --- /dev/null +++ b/log4j-streams/src/test/java/org/apache/logging/log4j/streams/StreamTesting.java @@ -0,0 +1,61 @@ +/* + * 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.logging.log4j.streams; + +import static org.hamcrest.core.StringStartsWith.startsWith; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThat; + +import java.util.List; + +import org.apache.logging.log4j.Level; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.junit.InitialLoggerContext; +import org.apache.logging.log4j.test.appender.ListAppender; +import org.junit.Before; +import org.junit.ClassRule; +import org.junit.Ignore; + +@Ignore +public class StreamTesting { + protected final static String NEWLINE = System.getProperty("line.separator"); + protected final static Level LEVEL = Level.ERROR; + protected final static String FIRST = "first"; + protected final static String LAST = "last"; + + @ClassRule + public static InitialLoggerContext ctx = new InitialLoggerContext("log4j2-streams-unit-test.xml"); + + protected static Logger getLogger() { + return ctx.getLogger("UnitTestLogger"); + } + + @Before + public void clearAppender() { + ((ListAppender) ctx.getAppender("UnitTest")).clear(); + } + + protected void assertMessages(final String... messages) { + List<String> actualMsgs = ((ListAppender) ctx.getAppender("UnitTest")).getMessages(); + assertEquals("Unexpected number of results.", messages.length, actualMsgs.size()); + for (int i = 0; i < messages.length; i++) { + final String start = LEVEL.name() + ' ' + messages[i]; + assertThat(actualMsgs.get(i), startsWith(start)); + } + } +} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1167a72d/log4j-streams/src/test/resources/log4j2-streams-calling-info.xml ---------------------------------------------------------------------- diff --git a/log4j-streams/src/test/resources/log4j2-streams-calling-info.xml b/log4j-streams/src/test/resources/log4j2-streams-calling-info.xml new file mode 100644 index 0000000..5f8dfd9 --- /dev/null +++ b/log4j-streams/src/test/resources/log4j2-streams-calling-info.xml @@ -0,0 +1,30 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ~ 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. + --> +<Configuration name="CallerInformationTest" status="error" packages="org.apache.logging.log4j.test"> + <Appenders> + <List name="ClassAndMethod"> + <PatternLayout pattern="%class.%method"/> + </List> + </Appenders> + <Loggers> + <Logger name="ClassAndMethodLogger" level="info"> + <AppenderRef ref="ClassAndMethod"/> + </Logger> + <Root level="off"/> + </Loggers> +</Configuration> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1167a72d/log4j-streams/src/test/resources/log4j2-streams-unit-test.xml ---------------------------------------------------------------------- diff --git a/log4j-streams/src/test/resources/log4j2-streams-unit-test.xml b/log4j-streams/src/test/resources/log4j2-streams-unit-test.xml new file mode 100644 index 0000000..d6f0211 --- /dev/null +++ b/log4j-streams/src/test/resources/log4j2-streams-unit-test.xml @@ -0,0 +1,30 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ~ 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. + --> +<Configuration name="UnitTest" status="error" packages="org.apache.logging.log4j.test"> + <Appenders> + <List name="UnitTest"> + <PatternLayout pattern="%level %m%n"/> + </List> + </Appenders> + <Loggers> + <Logger name="UnitTestLogger" level="info"> + <AppenderRef ref="UnitTest"/> + </Logger> + <Root level="off"/> + </Loggers> +</Configuration> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1167a72d/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml index 4851f68..29b05af 100644 --- a/pom.xml +++ b/pom.xml @@ -994,6 +994,7 @@ <module>log4j-nosql</module> <module>log4j-web</module> <module>log4j-perf</module> + <module>log4j-streams</module> </modules> <profiles> <profile>
