Implement RecordingLogger based on org.slf4j.Logger

Jetty 10 uses slf4j for logging and deprecated its own Logger interface
org.eclipse.jetty.util.log.Logger.

Change-Id: I1b0c3a23e43190a50987175973725c3ad6e32f5f
This commit is contained in:
Matthias Sohn 2021-11-24 23:11:36 +01:00
parent c05d711bb7
commit 75c716f5d7
2 changed files with 129 additions and 136 deletions

View File

@ -29,7 +29,8 @@ Import-Package: javax.servlet;version="[2.5.0,5.0.0)",
org.eclipse.jgit.revwalk;version="[6.0.0,6.1.0)",
org.eclipse.jgit.transport;version="[6.0.0,6.1.0)",
org.eclipse.jgit.transport.resolver;version="[6.0.0,6.1.0)",
org.junit;version="[4.13,5.0.0)"
org.junit;version="[4.13,5.0.0)",
org.slf4j.helpers;version="[1.7.0,2.0.0)"
Export-Package: org.eclipse.jgit.junit.http;version="6.0.0";
uses:="org.eclipse.jgit.transport,
org.eclipse.jgit.junit,

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2010, Google Inc. and others
* Copyright (C) 2010, 2021 Google Inc. and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0 which is available at
@ -7,7 +7,6 @@
*
* SPDX-License-Identifier: BSD-3-Clause
*/
package org.eclipse.jgit.junit.http;
import java.text.MessageFormat;
@ -15,12 +14,12 @@
import java.util.Collections;
import java.util.List;
import org.eclipse.jetty.util.log.Logger;
import org.slf4j.helpers.MarkerIgnoringBase;
public class RecordingLogger extends MarkerIgnoringBase {
private static final long serialVersionUID = 1L;
/**
* Log warnings into an array for later inspection.
*/
public class RecordingLogger implements Logger {
private static List<Warning> warnings = new ArrayList<>();
/**
@ -60,8 +59,6 @@ public Warning(Throwable thrown) {
}
}
private final String name;
/**
* Constructor for <code>RecordingLogger</code>.
*/
@ -78,171 +75,166 @@ public RecordingLogger(String name) {
this.name = name;
}
/** {@inheritDoc} */
@Override
public Logger getLogger(@SuppressWarnings("hiding") String name) {
return new RecordingLogger(name);
public boolean isTraceEnabled() {
// Ignore (not relevant to test failures)
return false;
}
/** {@inheritDoc} */
@Override
public String getName() {
return name;
public void trace(String msg) {
// Ignore (not relevant to test failures)
}
/**
* Warning
*
* @param msg
* @param arg0
* @param arg1
*/
public void warn(String msg, Object arg0, Object arg1) {
synchronized (warnings) {
warnings.add(new Warning(MessageFormat.format(msg, arg0, arg1)));
}
}
/** {@inheritDoc} */
@Override
public void warn(String msg, Throwable th) {
synchronized (warnings) {
warnings.add(new Warning(msg, th));
}
public void trace(String format, Object arg) {
// Ignore (not relevant to test failures)
}
/**
* Warning
*
* @param msg
* warning message
*/
@Override
public void trace(String format, Object arg1, Object arg2) {
// Ignore (not relevant to test failures)
}
@Override
public void trace(String format, Object... arguments) {
// Ignore (not relevant to test failures)
}
@Override
public void trace(String msg, Throwable t) {
// Ignore (not relevant to test failures)
}
@Override
public boolean isDebugEnabled() {
return false;
}
@Override
public void debug(String msg) {
// Ignore (not relevant to test failures)
}
@Override
public void debug(String format, Object arg) {
// Ignore (not relevant to test failures)
}
@Override
public void debug(String format, Object arg1, Object arg2) {
// Ignore (not relevant to test failures)
}
@Override
public void debug(String format, Object... arguments) {
// Ignore (not relevant to test failures)
}
@Override
public void debug(String msg, Throwable t) {
// Ignore (not relevant to test failures)
}
@Override
public boolean isInfoEnabled() {
return false;
}
@Override
public void info(String msg) {
// Ignore (not relevant to test failures)
}
@Override
public void info(String format, Object arg) {
// Ignore (not relevant to test failures)
}
@Override
public void info(String format, Object arg1, Object arg2) {
// Ignore (not relevant to test failures)
}
@Override
public void info(String format, Object... arguments) {
// Ignore (not relevant to test failures)
}
@Override
public void info(String msg, Throwable t) {
// Ignore (not relevant to test failures)
}
@Override
public boolean isWarnEnabled() {
return true;
}
@Override
public void warn(String msg) {
synchronized (warnings) {
warnings.add(new Warning(msg));
}
}
/**
* Debug log
*
* @param msg
* @param arg0
* @param arg1
*/
public void debug(String msg, Object arg0, Object arg1) {
// Ignore (not relevant to test failures)
}
/** {@inheritDoc} */
@Override
public void debug(String msg, Throwable th) {
// Ignore (not relevant to test failures)
public void warn(String format, Object arg) {
warn(format, Collections.singleton(arg));
}
/**
* Debug log
*
* @param msg
* debug message
*/
public void debug(String msg) {
// Ignore (not relevant to test failures)
}
/**
* Info
*
* @param msg
* @param arg0
* @param arg1
*/
public void info(String msg, Object arg0, Object arg1) {
// Ignore (not relevant to test failures)
}
/**
* Info
*
* @param msg
*/
public void info(String msg) {
// Ignore (not relevant to test failures)
}
/** {@inheritDoc} */
@Override
public boolean isDebugEnabled() {
public void warn(String format, Object... arguments) {
synchronized (warnings) {
int i = 0;
int index = format.indexOf("{}");
while (index >= 0) {
format = format.replaceFirst("\\{\\}", "{" + i++ + "}");
index = format.indexOf("{}");
}
warnings.add(new Warning(MessageFormat.format(format, arguments)));
}
}
@Override
public void warn(String format, Object arg1, Object arg2) {
warn(format, new Object[] { arg1, arg2 });
}
@Override
public void warn(String msg, Throwable t) {
synchronized (warnings) {
warnings.add(new Warning(msg, t));
}
}
@Override
public boolean isErrorEnabled() {
return false;
}
/** {@inheritDoc} */
@Override
public void setDebugEnabled(boolean enabled) {
public void error(String msg) {
// Ignore (not relevant to test failures)
}
/** {@inheritDoc} */
@Override
public void warn(String msg, Object... args) {
synchronized (warnings) {
int i = 0;
int index = msg.indexOf("{}");
while (index >= 0) {
msg = msg.replaceFirst("\\{\\}", "{" + i++ + "}");
index = msg.indexOf("{}");
}
warnings.add(new Warning(MessageFormat.format(msg, args)));
}
}
/** {@inheritDoc} */
@Override
public void warn(Throwable thrown) {
synchronized (warnings) {
warnings.add(new Warning(thrown));
}
}
/** {@inheritDoc} */
@Override
public void info(String msg, Object... args) {
public void error(String format, Object arg) {
// Ignore (not relevant to test failures)
}
/** {@inheritDoc} */
@Override
public void info(Throwable thrown) {
public void error(String format, Object arg1, Object arg2) {
// Ignore (not relevant to test failures)
}
/** {@inheritDoc} */
@Override
public void info(String msg, Throwable thrown) {
public void error(String format, Object... arguments) {
// Ignore (not relevant to test failures)
}
/** {@inheritDoc} */
@Override
public void debug(String msg, Object... args) {
// Ignore (not relevant to test failures)
}
/** {@inheritDoc} */
@Override
public void debug(Throwable thrown) {
// Ignore (not relevant to test failures)
}
/** {@inheritDoc} */
@Override
public void ignore(Throwable arg0) {
// Ignore (not relevant to test failures)
}
/** {@inheritDoc} */
@Override
public void debug(String msg, long value) {
public void error(String msg, Throwable t) {
// Ignore (not relevant to test failures)
}
}