mirror of
https://github.com/google/nomulus.git
synced 2025-06-28 23:33:36 +02:00
Migrate to internal FormattingLogger in preparation of migration to Flogger
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=197744904
This commit is contained in:
parent
86dd6bd59e
commit
fc60890136
188 changed files with 217 additions and 301 deletions
|
@ -8,6 +8,7 @@ java_library(
|
|||
name = "util",
|
||||
srcs = glob(["*.java"]),
|
||||
deps = [
|
||||
"//java/com/google/common/logging:formatting_logger",
|
||||
"//third_party/jaxb",
|
||||
"//third_party/objectify:objectify-v4_1",
|
||||
"@com_google_appengine_api_1_0_sdk",
|
||||
|
|
|
@ -17,6 +17,7 @@ package google.registry.util;
|
|||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
|
||||
import com.google.common.collect.AbstractSequentialIterator;
|
||||
import com.google.common.logging.FormattingLogger;
|
||||
import com.google.common.net.InetAddresses;
|
||||
import java.io.Serializable;
|
||||
import java.net.InetAddress;
|
||||
|
|
|
@ -1,133 +0,0 @@
|
|||
// 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.util;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.logging.Handler;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/** Logging wrapper. */
|
||||
public class FormattingLogger {
|
||||
|
||||
private final Logger logger;
|
||||
|
||||
/** Returns an instance using the caller's class name for the underlying logger's name. */
|
||||
public static FormattingLogger getLoggerForCallerClass() {
|
||||
return new FormattingLogger(new Exception().getStackTrace()[1].getClassName());
|
||||
}
|
||||
|
||||
private FormattingLogger(String name) {
|
||||
this.logger = Logger.getLogger(name);
|
||||
}
|
||||
|
||||
public void logfmt(Level level, Throwable cause, String fmt, Object... args) {
|
||||
log(level, cause, String.format(fmt, args));
|
||||
}
|
||||
|
||||
public void logfmt(Level level, String fmt, Object... args) {
|
||||
log(level, null, String.format(fmt, args));
|
||||
}
|
||||
|
||||
private void log(Level level, @Nullable Throwable cause, String msg) {
|
||||
StackTraceElement callerFrame =
|
||||
Arrays.stream(new Exception().getStackTrace())
|
||||
.filter(frame -> !frame.getClassName().equals(FormattingLogger.class.getName()))
|
||||
.findFirst()
|
||||
.get();
|
||||
if (cause == null) {
|
||||
logger.logp(level, callerFrame.getClassName(), callerFrame.getMethodName(), msg);
|
||||
} else {
|
||||
logger.logp(level, callerFrame.getClassName(), callerFrame.getMethodName(), msg, cause);
|
||||
}
|
||||
}
|
||||
|
||||
public void fine(String msg) {
|
||||
log(Level.FINE, null, msg);
|
||||
}
|
||||
|
||||
public void fine(Throwable cause, String msg) {
|
||||
log(Level.FINE, cause, msg);
|
||||
}
|
||||
|
||||
public void finefmt(String fmt, Object... args) {
|
||||
log(Level.FINE, null, String.format(fmt, args));
|
||||
}
|
||||
|
||||
public void finefmt(Throwable cause, String fmt, Object... args) {
|
||||
log(Level.FINE, cause, String.format(fmt, args));
|
||||
}
|
||||
|
||||
public void info(String msg) {
|
||||
log(Level.INFO, null, msg);
|
||||
}
|
||||
|
||||
public void info(Throwable cause, String msg) {
|
||||
log(Level.INFO, cause, msg);
|
||||
}
|
||||
|
||||
public void infofmt(String fmt, Object... args) {
|
||||
log(Level.INFO, null, String.format(fmt, args));
|
||||
}
|
||||
|
||||
public void infofmt(Throwable cause, String fmt, Object... args) {
|
||||
log(Level.INFO, cause, String.format(fmt, args));
|
||||
}
|
||||
|
||||
public void warning(String msg) {
|
||||
log(Level.WARNING, null, msg);
|
||||
}
|
||||
|
||||
public void warning(Throwable cause, String msg) {
|
||||
log(Level.WARNING, cause, msg);
|
||||
}
|
||||
|
||||
public void warningfmt(String fmt, Object... args) {
|
||||
log(Level.WARNING, null, String.format(fmt, args));
|
||||
}
|
||||
|
||||
public void warningfmt(Throwable cause, String fmt, Object... args) {
|
||||
log(Level.WARNING, cause, String.format(fmt, args));
|
||||
}
|
||||
|
||||
public void severe(String msg) {
|
||||
log(Level.SEVERE, null, msg);
|
||||
}
|
||||
|
||||
public void severe(Throwable cause, String msg) {
|
||||
log(Level.SEVERE, cause, msg);
|
||||
}
|
||||
|
||||
public void severefmt(String fmt, Object... args) {
|
||||
log(Level.SEVERE, null, String.format(fmt, args));
|
||||
}
|
||||
|
||||
public void severefmt(Throwable cause, String fmt, Object... args) {
|
||||
log(Level.SEVERE, cause, String.format(fmt, args));
|
||||
}
|
||||
|
||||
public boolean isLoggable(Level level) {
|
||||
return logger.isLoggable(level);
|
||||
}
|
||||
|
||||
public void addHandler(Handler handler) {
|
||||
logger.addHandler(handler);
|
||||
}
|
||||
|
||||
public void removeHandler(Handler handler) {
|
||||
logger.removeHandler(handler);
|
||||
}
|
||||
}
|
|
@ -17,6 +17,7 @@ package google.registry.util;
|
|||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.google.common.logging.FormattingLogger;
|
||||
import java.io.FilterInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
|
|
@ -17,6 +17,7 @@ package google.registry.util;
|
|||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.google.common.logging.FormattingLogger;
|
||||
import java.io.FilterOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
|
|
@ -22,6 +22,7 @@ import com.google.apphosting.api.ApiProxy;
|
|||
import com.google.apphosting.api.ApiProxy.Environment;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.logging.FormattingLogger;
|
||||
import java.util.Collections;
|
||||
import javax.inject.Inject;
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ import static com.google.common.math.IntMath.pow;
|
|||
import static google.registry.util.PredicateUtils.supertypeOf;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.logging.FormattingLogger;
|
||||
import java.io.Serializable;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.Callable;
|
||||
|
|
|
@ -22,6 +22,7 @@ import com.google.appengine.api.taskqueue.TaskOptions;
|
|||
import com.google.appengine.api.taskqueue.TransientFailureException;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.logging.FormattingLogger;
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
import javax.inject.Inject;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue