|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | + * contributor license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright ownership. |
| 5 | + * The ASF licenses this file to you under the Apache License, Version 2.0 |
| 6 | + * (the "License"); you may not use this file except in compliance with |
| 7 | + * the License. You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | +package org.apache.logging.log4j.core.appender; |
| 18 | + |
| 19 | +import static org.junit.jupiter.api.Assertions.assertFalse; |
| 20 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
| 21 | + |
| 22 | +import java.io.ByteArrayOutputStream; |
| 23 | +import java.io.PrintStream; |
| 24 | +import java.nio.charset.Charset; |
| 25 | +import org.apache.logging.log4j.LogManager; |
| 26 | +import org.apache.logging.log4j.Logger; |
| 27 | +import org.junit.jupiter.api.Test; |
| 28 | + |
| 29 | +class DefaultLayoutTest { |
| 30 | + @Test |
| 31 | + void testDefaultLayout() { |
| 32 | + PrintStream standardOutput = System.out; |
| 33 | + ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
| 34 | + |
| 35 | + System.setOut(new PrintStream(baos)); |
| 36 | + try { |
| 37 | + Logger log = LogManager.getLogger(getClass()); |
| 38 | + log.fatal("This is a fatal message"); |
| 39 | + log.error("This is an error message"); |
| 40 | + log.warn("This is a warning message"); |
| 41 | + |
| 42 | + String actualOutput = new String(baos.toByteArray(), Charset.defaultCharset()); |
| 43 | + assertTrue(actualOutput.contains("FATAL This is a fatal message" + System.lineSeparator())); |
| 44 | + assertTrue(actualOutput.contains("ERROR This is an error message" + System.lineSeparator())); |
| 45 | + assertFalse(actualOutput.contains("This is a warning message")); |
| 46 | + } finally { |
| 47 | + System.setOut(standardOutput); |
| 48 | + } |
| 49 | + } |
| 50 | +} |
0 commit comments