uk.org.lidalia.slf4jtest.LoggingEvent Maven / Gradle / Ivy
package uk.org.lidalia.slf4jtest;
import java.io.PrintStream;
import java.util.Collections;
import java.util.Map;
import org.joda.time.Instant;
import org.slf4j.Marker;
import org.slf4j.helpers.MessageFormatter;
import com.google.common.base.Function;
import com.google.common.base.Optional;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import uk.org.lidalia.lang.Identity;
import uk.org.lidalia.lang.RichObject;
import uk.org.lidalia.slf4jext.Level;
import static com.google.common.base.Optional.absent;
import static com.google.common.base.Optional.fromNullable;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.FluentIterable.from;
import static java.util.Arrays.asList;
/**
* Representation of a call to a logger for test assertion purposes.
*
* The contract of {@link #equals(Object)} and {@link #hashCode} is that they compare the results of:
*
* - {@link #getLevel()}
* - {@link #getMdc()}
* - {@link #getMarker()}
* - {@link #getThrowable()}
* - {@link #getMessage()}
* - {@link #getArguments()}
*
*
* They do NOT compare the results of {@link #getTimestamp()} or {@link #getCreatingLogger()} as this would render it impractical
* to create appropriate expected {@link LoggingEvent}s to compare against.
*
* Constructors and convenient static factory methods exist to create {@link LoggingEvent}s with appropriate
* defaults. These are not documented further as they should be self-evident.
*/
@SuppressWarnings({ "PMD.ExcessivePublicCount", "PMD.TooManyMethods" })
public class LoggingEvent extends RichObject {
public static LoggingEvent trace(final String message, final Object... arguments) {
return new LoggingEvent(Level.TRACE, message, arguments);
}
public static LoggingEvent trace(final Throwable throwable, final String message, final Object... arguments) {
return new LoggingEvent(Level.TRACE, throwable, message, arguments);
}
public static LoggingEvent trace(final Marker marker, final String message, final Object... arguments) {
return new LoggingEvent(Level.TRACE, marker, message, arguments);
}
public static LoggingEvent trace(
final Marker marker, final Throwable throwable, final String message, final Object... arguments) {
return new LoggingEvent(Level.TRACE, marker, throwable, message, arguments);
}
public static LoggingEvent trace(final Map mdc, final String message, final Object... arguments) {
return new LoggingEvent(Level.TRACE, mdc, message, arguments);
}
public static LoggingEvent trace(
final Map mdc, final Throwable throwable, final String message, final Object... arguments) {
return new LoggingEvent(Level.TRACE, mdc, throwable, message, arguments);
}
public static LoggingEvent trace(
final Map mdc, final Marker marker, final String message, final Object... arguments) {
return new LoggingEvent(Level.TRACE, mdc, marker, message, arguments);
}
public static LoggingEvent trace(
final Map mdc,
final Marker marker,
final Throwable throwable,
final String message,
final Object... arguments) {
return new LoggingEvent(Level.TRACE, mdc, marker, throwable, message, arguments);
}
public static LoggingEvent debug(final String message, final Object... arguments) {
return new LoggingEvent(Level.DEBUG, message, arguments);
}
public static LoggingEvent debug(final Throwable throwable, final String message, final Object... arguments) {
return new LoggingEvent(Level.DEBUG, throwable, message, arguments);
}
public static LoggingEvent debug(final Marker marker, final String message, final Object... arguments) {
return new LoggingEvent(Level.DEBUG, marker, message, arguments);
}
public static LoggingEvent debug(
final Marker marker, final Throwable throwable, final String message, final Object... arguments) {
return new LoggingEvent(Level.DEBUG, marker, throwable, message, arguments);
}
public static LoggingEvent debug(final Map mdc, final String message, final Object... arguments) {
return new LoggingEvent(Level.DEBUG, mdc, message, arguments);
}
public static LoggingEvent debug(
final Map mdc, final Throwable throwable, final String message, final Object... arguments) {
return new LoggingEvent(Level.DEBUG, mdc, throwable, message, arguments);
}
public static LoggingEvent debug(
final Map mdc, final Marker marker, final String message, final Object... arguments) {
return new LoggingEvent(Level.DEBUG, mdc, marker, message, arguments);
}
public static LoggingEvent debug(
final Map mdc,
final Marker marker,
final Throwable throwable,
final String message,
final Object... arguments) {
return new LoggingEvent(Level.DEBUG, mdc, marker, throwable, message, arguments);
}
public static LoggingEvent info(final String message, final Object... arguments) {
return new LoggingEvent(Level.INFO, message, arguments);
}
public static LoggingEvent info(final Throwable throwable, final String message, final Object... arguments) {
return new LoggingEvent(Level.INFO, throwable, message, arguments);
}
public static LoggingEvent info(final Marker marker, final String message, final Object... arguments) {
return new LoggingEvent(Level.INFO, marker, message, arguments);
}
public static LoggingEvent info(
final Marker marker, final Throwable throwable, final String message, final Object... arguments) {
return new LoggingEvent(Level.INFO, marker, throwable, message, arguments);
}
public static LoggingEvent info(final Map mdc, final String message, final Object... arguments) {
return new LoggingEvent(Level.INFO, mdc, message, arguments);
}
public static LoggingEvent info(
final Map mdc, final Throwable throwable, final String message, final Object... arguments) {
return new LoggingEvent(Level.INFO, mdc, throwable, message, arguments);
}
public static LoggingEvent info(
final Map mdc, final Marker marker, final String message, final Object... arguments) {
return new LoggingEvent(Level.INFO, mdc, marker, message, arguments);
}
public static LoggingEvent info(
final Map mdc,
final Marker marker,
final Throwable throwable,
final String message,
final Object... arguments) {
return new LoggingEvent(Level.INFO, mdc, marker, throwable, message, arguments);
}
public static LoggingEvent warn(final String message, final Object... arguments) {
return new LoggingEvent(Level.WARN, message, arguments);
}
public static LoggingEvent warn(final Throwable throwable, final String message, final Object... arguments) {
return new LoggingEvent(Level.WARN, throwable, message, arguments);
}
public static LoggingEvent warn(final Marker marker, final String message, final Object... arguments) {
return new LoggingEvent(Level.WARN, marker, message, arguments);
}
public static LoggingEvent warn(
final Marker marker, final Throwable throwable, final String message, final Object... arguments) {
return new LoggingEvent(Level.WARN, marker, throwable, message, arguments);
}
public static LoggingEvent warn(final Map mdc, final String message, final Object... arguments) {
return new LoggingEvent(Level.WARN, mdc, message, arguments);
}
public static LoggingEvent warn(
final Map mdc, final Throwable throwable, final String message, final Object... arguments) {
return new LoggingEvent(Level.WARN, mdc, throwable, message, arguments);
}
public static LoggingEvent warn(
final Map mdc, final Marker marker, final String message, final Object... arguments) {
return new LoggingEvent(Level.WARN, mdc, marker, message, arguments);
}
public static LoggingEvent warn(
final Map mdc,
final Marker marker,
final Throwable throwable,
final String message,
final Object... arguments) {
return new LoggingEvent(Level.WARN, mdc, marker, throwable, message, arguments);
}
public static LoggingEvent error(final String message, final Object... arguments) {
return new LoggingEvent(Level.ERROR, message, arguments);
}
public static LoggingEvent error(final Throwable throwable, final String message, final Object... arguments) {
return new LoggingEvent(Level.ERROR, throwable, message, arguments);
}
public static LoggingEvent error(final Marker marker, final String message, final Object... arguments) {
return new LoggingEvent(Level.ERROR, marker, message, arguments);
}
public static LoggingEvent error(
final Marker marker, final Throwable throwable, final String message, final Object... arguments) {
return new LoggingEvent(Level.ERROR, marker, throwable, message, arguments);
}
public static LoggingEvent error(final Map mdc, final String message, final Object... arguments) {
return new LoggingEvent(Level.ERROR, mdc, message, arguments);
}
public static LoggingEvent error(
final Map mdc, final Throwable throwable, final String message, final Object... arguments) {
return new LoggingEvent(Level.ERROR, mdc, throwable, message, arguments);
}
public static LoggingEvent error(
final Map mdc, final Marker marker, final String message, final Object... arguments) {
return new LoggingEvent(Level.ERROR, mdc, marker, message, arguments);
}
public static LoggingEvent error(
final Map mdc,
final Marker marker,
final Throwable throwable,
final String message,
final Object... arguments) {
return new LoggingEvent(Level.ERROR, mdc, marker, throwable, message, arguments);
}
public LoggingEvent(final Level level, final String message, final Object... arguments) {
this(level, Collections.emptyMap(), Optional.absent(), Optional.absent(),
message, arguments);
}
public LoggingEvent(final Level level, final Throwable throwable, final String message, final Object... arguments) {
this(level, Collections.emptyMap(), Optional.absent(), fromNullable(throwable), message, arguments);
}
public LoggingEvent(final Level level, final Marker marker, final String message, final Object... arguments) {
this(level, Collections.emptyMap(), fromNullable(marker), Optional.absent(), message, arguments);
}
public LoggingEvent(
final Level level, final Marker marker, final Throwable throwable, final String message, final Object... arguments) {
this(level, Collections.emptyMap(), fromNullable(marker), fromNullable(throwable), message, arguments);
}
public LoggingEvent(final Level level, final Map mdc, final String message, final Object... arguments) {
this(level, mdc, Optional.absent(), Optional.absent(), message, arguments);
}
public LoggingEvent(
final Level level,
final Map mdc,
final Throwable throwable,
final String message,
final Object... arguments) {
this(level, mdc, Optional.absent(), fromNullable(throwable), message, arguments);
}
public LoggingEvent(
final Level level,
final Map mdc,
final Marker marker,
final String message,
final Object... arguments) {
this(level, mdc, fromNullable(marker), Optional.absent(), message, arguments);
}
public LoggingEvent(
final Level level,
final Map mdc,
final Marker marker,
final Throwable throwable,
final String message,
final Object... arguments) {
this(level, mdc, fromNullable(marker), fromNullable(throwable), message, arguments);
}
private LoggingEvent(
final Level level,
final Map mdc,
final Optional marker,
final Optional throwable,
final String message,
final Object... arguments) {
this(Optional.absent(), level, mdc, marker, throwable, message, arguments);
}
LoggingEvent(
final Optional creatingLogger,
final Level level,
final Map mdc,
final Optional marker,
final Optional throwable,
final String message,
final Object... arguments) {
super();
this.creatingLogger = creatingLogger;
this.level = checkNotNull(level);
this.mdc = ImmutableMap.copyOf(mdc);
this.marker = checkNotNull(marker);
this.throwable = checkNotNull(throwable);
this.message = checkNotNull(message);
this.arguments = from(asList(arguments)).transform(new Function
© 2015 - 2024 Weber Informatics LLC | Privacy Policy