Skip to content

Commit

Permalink
more complete initialization
Browse files Browse the repository at this point in the history
Signed-off-by: Ceki Gulcu <[email protected]>
  • Loading branch information
ceki committed Apr 4, 2024
1 parent d2f1cff commit 7587630
Showing 1 changed file with 40 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,38 +12,66 @@
* as published by the Free Software Foundation.
*/

package ch.qos.logback.core.issue.logback_1759;
package ch.qos.logback.classic.issue.logback_1759;

import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.Logger;
import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.encoder.PatternLayoutEncoder;
import ch.qos.logback.classic.spi.LoggingEvent;
import ch.qos.logback.classic.util.LogbackMDCAdapter;
import ch.qos.logback.core.ConsoleAppender;
import ch.qos.logback.core.Context;
import ch.qos.logback.core.ContextBase;
import ch.qos.logback.core.encoder.EchoEncoder;
import ch.qos.logback.core.util.StatusPrinter2;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.slf4j.spi.MDCAdapter;

public class Logback1759Test {

Context context = new ContextBase();
EchoEncoder echoEncoder = new EchoEncoder();
ConsoleAppender consoleAppender = new ConsoleAppender();
LoggerContext context = new LoggerContext();
Logger logger = context.getLogger("toto.foo");
StatusPrinter2 statusPrinter2 = new StatusPrinter2();
PatternLayoutEncoder patternLayoutEncoder = null;
ConsoleAppender consoleAppender = null;
LogbackMDCAdapter logbackMDCAdapter = new LogbackMDCAdapter();

@BeforeEach
public void setup() {
context.setMDCAdapter(logbackMDCAdapter);
init();
}

void init() {
System.out.println("Init called");
this.patternLayoutEncoder = new PatternLayoutEncoder();
patternLayoutEncoder.setContext(context);
patternLayoutEncoder.setPattern("%highlight(%level) %message%n");
patternLayoutEncoder.start();

this.consoleAppender = new ConsoleAppender();
consoleAppender.setContext(context);
echoEncoder.setContext(context);
echoEncoder.start();
consoleAppender.setEncoder(echoEncoder);
consoleAppender.setEncoder(patternLayoutEncoder);
}

@Test
public void smoke() {
consoleAppender.setWithJansi(true);
consoleAppender.start();

consoleAppender.doAppend("hello 1");
//String fqcn, Logger logger, Level level, String message, Throwable throwable,
// Object[] argArray

LoggingEvent le = new LoggingEvent("x", logger, Level.INFO, "hello", null, null);

consoleAppender.doAppend(le);

consoleAppender.stop();

init();
consoleAppender.start();
consoleAppender.doAppend("hello 2");

consoleAppender.doAppend(le);

//statusPrinter2.print(context);
}
}

0 comments on commit 7587630

Please sign in to comment.