Skip to content
This repository has been archived by the owner on Jan 12, 2021. It is now read-only.

Adding new loggerAPIs to avoid varagrs #61

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions logging/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@
<artifactId>mockito-all</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-core</artifactId>
<version>1.19</version>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-generator-annprocess</artifactId>
<version>1.19</version>
</dependency>
</dependencies>

</project>
53 changes: 53 additions & 0 deletions logging/src/jmh/java/com/facebook/logging/LoggerBenchmark.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.facebook.logging;

import java.util.concurrent.TimeUnit;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Fork;
import org.openjdk.jmh.annotations.Measurement;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.OutputTimeUnit;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.Warmup;

@State(Scope.Benchmark)
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.MICROSECONDS)
@Fork(value = 1, warmups = 1)
@Warmup(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
@Measurement(iterations = 30, time = 1, timeUnit = TimeUnit.SECONDS)
public class LoggerBenchmark {

Logger logger;

@Setup
public void init() {
logger = LoggerImpl.getClassLogger();
}

public static void main(String[] args) throws Exception {
org.openjdk.jmh.Main.main(args);
}

@Benchmark
public void benchmarkWithNoArg() {
logger.warn("test");
}

@Benchmark
public void benchmarkWithOneArg() {
logger.warn("test with %s", "arg1");
}

@Benchmark
public void benchmarkWithTwoArgs() {
logger.warn("test with %s, %s", "arg1", "arg2");
}

@Benchmark
public void benchmarkWithThreeArgs() {
logger.warn("test with %s, %s, %s", "arg1", "arg2", "arg3");
}
}
32 changes: 32 additions & 0 deletions logging/src/jmh/resources/log4j.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#
# Copyright (C) 2012 Facebook, Inc.
#
# 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.
#

log4j.rootLogger=INFO,console

# Logging Threshold
log4j.threshhold=INFO

#
# console
# Add "console" to rootlogger above if you want to use this
#
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.target=System.err
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=%d{yyyy-MM-dd}T%d{HH:mm:ss} %p %c{2}: %m%n

log4j.logger.com.facebook.logging=INFO
log4j.logger.org.apache.thrift=INFO
150 changes: 150 additions & 0 deletions logging/src/main/java/com/facebook/logging/CompositeLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,36 @@ protected boolean getValue(Logger log) {
});
}

@Override
public void trace(String message) {
logAll(
log -> {
if (log.isTraceEnabled()) {
log.trace(message);
}
});
}

@Override
public void trace(String format, Object arg1) {
logAll(
log -> {
if (log.isTraceEnabled()) {
log.trace(format, arg1);
}
});
}

@Override
public void trace(String format, Object arg1, Object arg2) {
logAll(
log -> {
if (log.isTraceEnabled()) {
log.trace(format, arg1, arg2);
}
});
}

@Override
public void trace(String format, Object... args) {
logAll(
Expand All @@ -101,6 +131,36 @@ public void trace(Throwable t, String format, Object... args) {
});
}

@Override
public void debug(String message) {
logAll(
log -> {
if (log.isTraceEnabled()) {
log.debug(message);
}
});
}

@Override
public void debug(String format, Object arg1) {
logAll(
log -> {
if (log.isDebugEnabled()) {
log.debug(format, arg1);
}
});
}

@Override
public void debug(String format, Object arg1, Object arg2) {
logAll(
log -> {
if (log.isDebugEnabled()) {
log.debug(format, arg1, arg2);
}
});
}

@Override
public void debug(String format, Object... args) {
logAll(
Expand Down Expand Up @@ -131,6 +191,36 @@ public void debug(String message, Throwable throwable) {
});
}

@Override
public void info(String message) {
logAll(
log -> {
if (log.isTraceEnabled()) {
log.info(message);
}
});
}

@Override
public void info(String format, Object arg1) {
logAll(
log -> {
if (log.isInfoEnabled()) {
log.info(format, arg1);
}
});
}

@Override
public void info(String format, Object arg1, Object arg2) {
logAll(
log -> {
if (log.isInfoEnabled()) {
log.info(format, arg1, arg2);
}
});
}

@Override
public void info(String format, Object... args) {
logAll(
Expand Down Expand Up @@ -161,6 +251,36 @@ public void info(String message, Throwable throwable) {
});
}

@Override
public void warn(String message) {
logAll(
log -> {
if (log.isTraceEnabled()) {
log.warn(message);
}
});
}

@Override
public void warn(String format, Object arg1) {
logAll(
log -> {
if (log.isWarnEnabled()) {
log.warn(format, arg1);
}
});
}

@Override
public void warn(String format, Object arg1, Object arg2) {
logAll(
log -> {
if (log.isWarnEnabled()) {
log.warn(format, arg1, arg2);
}
});
}

@Override
public void warn(String format, Object... args) {
logAll(
Expand Down Expand Up @@ -191,6 +311,36 @@ public void warn(String message, Throwable throwable) {
});
}

@Override
public void error(String message) {
logAll(
log -> {
if (log.isTraceEnabled()) {
log.error(message);
}
});
}

@Override
public void error(String format, Object arg1) {
logAll(
log -> {
if (log.isErrorEnabled()) {
log.error(format, arg1);
}
});
}

@Override
public void error(String format, Object arg1, Object arg2) {
logAll(
log -> {
if (log.isErrorEnabled()) {
log.error(format, arg1, arg2);
}
});
}

@Override
public void error(String format, Object... args) {
logAll(
Expand Down
75 changes: 75 additions & 0 deletions logging/src/main/java/com/facebook/logging/DynamicLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,21 @@ public boolean isErrorEnabled() {
return getLogger().isErrorEnabled();
}

@Override
public void trace(String message) {
getLogger().trace(message);
}

@Override
public void trace(String format, Object arg1) {
getLogger().trace(format, arg1);
}

@Override
public void trace(String format, Object arg1, Object arg2) {
getLogger().trace(format, arg1, arg2);
}

@Override
public void trace(String format, Object... args) {
getLogger().trace(format, args);
Expand All @@ -61,6 +76,21 @@ public void trace(Throwable t, String format, Object... args) {
getLogger().trace(t, format, args);
}

@Override
public void debug(String message) {
getLogger().debug(message);
}

@Override
public void debug(String format, Object arg1) {
getLogger().debug(format, arg1);
}

@Override
public void debug(String format, Object arg1, Object arg2) {
getLogger().debug(format, arg1, arg2);
}

@Override
public void debug(String format, Object... args) {
getLogger().debug(format, args);
Expand All @@ -77,6 +107,21 @@ public void debug(String message, Throwable throwable) {
getLogger().debug(message, throwable);
}

@Override
public void info(String message) {
getLogger().info(message);
}

@Override
public void info(String format, Object arg1) {
getLogger().info(format, arg1);
}

@Override
public void info(String format, Object arg1, Object arg2) {
getLogger().info(format, arg1, arg2);
}

@Override
public void info(String format, Object... args) {
getLogger().info(format, args);
Expand All @@ -93,6 +138,21 @@ public void info(String message, Throwable throwable) {
getLogger().info(message, throwable);
}

@Override
public void warn(String message) {
getLogger().warn(message);
}

@Override
public void warn(String format, Object arg1) {
getLogger().warn(format, arg1);
}

@Override
public void warn(String format, Object arg1, Object arg2) {
getLogger().warn(format, arg1, arg2);
}

@Override
public void warn(String format, Object... args) {
getLogger().warn(format, args);
Expand All @@ -109,6 +169,21 @@ public void warn(String message, Throwable throwable) {
getLogger().warn(message, throwable);
}

@Override
public void error(String message) {
getLogger().error(message);
}

@Override
public void error(String format, Object arg1) {
getLogger().error(format, arg1);
}

@Override
public void error(String format, Object arg1, Object arg2) {
getLogger().error(format, arg1, arg2);
}

@Override
public void error(String format, Object... args) {
getLogger().error(format, args);
Expand Down
Loading