package org.tinylog.core.test.log;

import org.tinylog.core.Level;
import org.tinylog.core.backend.LevelVisibility;
import org.tinylog.core.backend.LoggingBackend;
import org.tinylog.core.format.message.MessageFormatter;
import org.tinylog.core.runtime.StackTraceLocation;

/**
 * Logging backend for storing all issued log entries in a passed {@link Log}.
 */
class CaptureLoggingBackend implements LoggingBackend {

	private final Log log;
	private final Level visibleLevel;

	/**
	 * @param log All issued log entries will be stored in this {@link Log}
	 * @param visibleLevel The minimum visible severity level for {@link #getLevelVisibility(String)}
	 */
	CaptureLoggingBackend(Log log, Level visibleLevel) {
		this.log = log;
		this.visibleLevel = visibleLevel;
	}

	@Override
	public LevelVisibility getLevelVisibility(String tag) {
		return new LevelVisibility(
			Level.TRACE.ordinal() <= visibleLevel.ordinal(),
			Level.DEBUG.ordinal() <= visibleLevel.ordinal(),
			Level.INFO.ordinal() <= visibleLevel.ordinal(),
			Level.WARN.ordinal() <= visibleLevel.ordinal(),
			Level.ERROR.ordinal() <= visibleLevel.ordinal()
		);
	}

	@Override
	public boolean isEnabled(StackTraceLocation location, String tag, Level level) {
		return level.ordinal() <= log.getMinLevel().ordinal();
	}

	@Override
	public void log(StackTraceLocation location, String tag, Level level, Throwable throwable, Object message,
			Object[] arguments, MessageFormatter formatter) {
		String output = arguments == null ? String.valueOf(message) : formatter.format(message.toString(), arguments);
		log.add(new LogEntry(location.getCallerClassName(), tag, level, throwable, output));
	}

}

@@ -29,16 +29,53 @@
 t.log;%0A%0A
+import java.util.function.Supplier;%0A%0A
 import o
@@ -1498,24 +1498,169 @@
 %7B%0A%09%09
-String output = 
+if (message instanceof Supplier%3C?%3E) %7B%0A%09%09%09message = ((Supplier%3C?%3E) message).get();%0A%09%09%7D%0A%0A%09%09String output;%0A%0A%09%09if (message == null) %7B%0A%09%09%09output = null;%0A%09%09%7D else if (
 argu
@@ -1676,10 +1676,23 @@
 null
- ?
+) %7B%0A%09%09%09output =
  Str
@@ -1715,10 +1715,32 @@
 age)
- :
+;%0A%09%09%7D else %7B%0A%09%09%09output =
  for
@@ -1785,16 +1785,21 @@
 ments);%0A
+%09%09%7D%0A%0A
 %09%09log.ad

Support null and lazy messages by capture logging backend