mirror of
https://github.com/google/nomulus.git
synced 2025-04-30 20:17:51 +02:00
The logging for exceptions in FlowRunner - always at WARNING - has long been sub-optimal. For EppExceptions it's too aggressive/spammy to log at WARNING because it's generally not actionable - EppException gets properly thrown for all kinds of ordinary reasons (trying to create a resource when one already exists with that foreign key) and/or for client misbehavior that we can't control (sending bad parameter values, etc.). For non-EppException RuntimeExceptions, it's redundant with existing logging in EppController. This CL resolves this by removing that logging in FlowRunner entirely in favor of the EppController logging, where we're now logging EppExceptions at INFO in parallel with the existing logging of RuntimeExceptions at SEVERE. This has the benefit that we're now logging EppExceptions that come from FlowPicker (by way of EppExceptionInProviderException), which previously were unlogged. Note however that this does mean that in places where we run FlowRunner without EppController - exclusively test code as it stands today - we'd no longer be logging EppExceptions. If that seems like a loss, we could either reinstate logging there (at INFO) and just deal with redundant messages for most EppExceptions, or we could add it manually to places where we call FlowRunner.run() in tests and avoid the redundancy that way. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=154733365
48 lines
1.8 KiB
Java
48 lines
1.8 KiB
Java
// Copyright 2017 The Nomulus Authors. All Rights Reserved.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
package google.registry.testing;
|
|
|
|
import com.google.common.base.Predicate;
|
|
import com.google.common.collect.Iterables;
|
|
import com.google.common.testing.TestLogHandler;
|
|
import java.util.logging.LogRecord;
|
|
|
|
/** Utility methods for working with Guava's {@link TestLogHandler}. */
|
|
public final class TestLogHandlerUtils {
|
|
private TestLogHandlerUtils() {}
|
|
|
|
/**
|
|
* Find the first log message stored in the handler that has the provided prefix, and return that
|
|
* message with the prefix stripped off.
|
|
*/
|
|
public static String findFirstLogMessageByPrefix(TestLogHandler handler, String prefix) {
|
|
return findFirstLogRecordWithMessagePrefix(handler, prefix)
|
|
.getMessage()
|
|
.replaceFirst("^" + prefix, "");
|
|
}
|
|
|
|
/** Returns the first log record stored in handler whose message has the provided prefix. */
|
|
public static LogRecord findFirstLogRecordWithMessagePrefix(
|
|
TestLogHandler handler, final String prefix) {
|
|
return Iterables.find(
|
|
handler.getStoredLogRecords(),
|
|
new Predicate<LogRecord>() {
|
|
@Override
|
|
public boolean apply(LogRecord logRecord) {
|
|
return logRecord.getMessage().startsWith(prefix);
|
|
}
|
|
});
|
|
}
|
|
}
|