Skip to content
This repository has been archived by the owner on Mar 3, 2023. It is now read-only.

Add SLF4JBridgeHandler #3809

Merged
Show file tree
Hide file tree
Changes from 5 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
2 changes: 2 additions & 0 deletions eco/src/java/org/apache/heron/eco/Eco.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.apache.heron.api.Config;
import org.apache.heron.api.utils.Slf4jUtils;
import org.apache.heron.eco.builder.BoltBuilder;
import org.apache.heron.eco.builder.BuilderUtility;
import org.apache.heron.eco.builder.ComponentBuilder;
Expand Down Expand Up @@ -132,6 +133,7 @@ public void submit(FileInputStream fileInputStream,
}

public static void main(String[] args) throws Exception {
Slf4jUtils.installSLF4JBridge();
Options options = constructOptions();

CommandLineParser parser = new DefaultParser();
Expand Down
1 change: 1 addition & 0 deletions heron/api/src/java/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ api_deps_files = \
":classification",
"//heron/common/src/java:basics-java",
"@maven//:javax_xml_bind_jaxb_api",
"@maven//:org_slf4j_jul_to_slf4j",
]

# Low Level Api
Expand Down
34 changes: 34 additions & 0 deletions heron/api/src/java/org/apache/heron/api/utils/Slf4jUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 org.apache.heron.api.utils;

import org.slf4j.bridge.SLF4JBridgeHandler;

public final class Slf4jUtils {
private Slf4jUtils() {
}

public static void installSLF4JBridge() {
if (!SLF4JBridgeHandler.isInstalled()) {
SLF4JBridgeHandler.removeHandlersForRootLogger();
SLF4JBridgeHandler.install();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.apache.heron.api.utils.Slf4jUtils;
import org.apache.heron.common.basics.NIOLooper;
import org.apache.heron.common.basics.SingletonRegistry;
import org.apache.heron.common.config.SystemConfig;
Expand Down Expand Up @@ -212,6 +213,7 @@ private static IStatefulStorage setupStatefulStorage(

public static void main(String[] args) throws IOException,
ParseException, CheckpointManagerException {
Slf4jUtils.installSLF4JBridge();
Options options = constructOptions();
Options helpOptions = constructHelpOptions();
CommandLineParser parser = new DefaultParser();
Expand Down
1 change: 1 addition & 0 deletions heron/downloaders/src/java/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ downloader_deps = [
"@maven//:commons_cli_commons_cli",
"//third_party/java:dlog-java",
"@maven//:io_netty_netty_all",
"@maven//:org_slf4j_jul_to_slf4j",
]

java_library(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import java.nio.file.Path;
import java.nio.file.Paths;

import org.slf4j.bridge.SLF4JBridgeHandler;

import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.DefaultParser;
Expand Down Expand Up @@ -127,6 +129,8 @@ private static Options constructCliOptions() {

// takes topology package URI and extracts it to a directory
public static void main(String[] args) throws Exception {
SLF4JBridgeHandler.removeHandlersForRootLogger();
SLF4JBridgeHandler.install();
CommandLineParser parser = new DefaultParser();
Options slaManagerCliOptions = constructCliOptions();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.apache.heron.api.utils.Slf4jUtils;
import org.apache.heron.classification.InterfaceStability.Evolving;
import org.apache.heron.classification.InterfaceStability.Unstable;
import org.apache.heron.common.basics.SingletonRegistry;
Expand Down Expand Up @@ -152,6 +153,7 @@ public HealthManager(Config config, AbstractModule baseModule) {
}

public static void main(String[] args) throws Exception {
Slf4jUtils.installSLF4JBridge();
CommandLineParser parser = new DefaultParser();
Options slaManagerCliOptions = constructCliOptions();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.apache.heron.api.utils.Slf4jUtils;
import org.apache.heron.common.basics.NIOLooper;
import org.apache.heron.common.basics.SysUtils;
import org.apache.heron.common.config.SystemConfig;
Expand Down Expand Up @@ -284,6 +285,7 @@ private static void usage(Options options) {
}

public static void main(String[] args) throws Exception {
Slf4jUtils.installSLF4JBridge();
Options options = constructOptions();
Options helpOptions = constructHelpOptions();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpServer;

import org.apache.heron.api.utils.Slf4jUtils;
import org.apache.heron.metricscachemgr.metricscache.MetricsCache;
import org.apache.heron.proto.tmanager.TopologyManager;
import org.apache.heron.spi.utils.NetworkUtils;
Expand Down Expand Up @@ -95,6 +96,7 @@ public MetricsCacheManagerHttpServer(MetricsCache cache, int port) throws IOExce
*/
public static void main(String[] args)
throws ExecutionException, InterruptedException, IOException {
Slf4jUtils.installSLF4JBridge();
if (args.length < 3) {
System.out.println(
"Usage: java MetricsQuery <host:port> <component_name> <metrics_name>");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.apache.heron.api.metric.MultiCountMetric;
import org.apache.heron.api.utils.Slf4jUtils;
import org.apache.heron.common.basics.Communicator;
import org.apache.heron.common.basics.ExecutorLooper;
import org.apache.heron.common.basics.NIOLooper;
Expand Down Expand Up @@ -329,6 +330,7 @@ private static void usage(Options options) {
}

public static void main(String[] args) throws Exception {
Slf4jUtils.installSLF4JBridge();
final Options options = constructOptions();
final Options helpOptions = constructHelpOptions();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.apache.heron.api.utils.Slf4jUtils;
import org.apache.heron.common.basics.DryRunFormatType;
import org.apache.heron.common.basics.SysUtils;
import org.apache.heron.common.utils.logging.LoggingHelper;
Expand Down Expand Up @@ -224,7 +225,7 @@ private static Options constructHelpOptions() {
public static void main(String[] args)
throws ClassNotFoundException, IllegalAccessException,
InstantiationException, IOException, ParseException {

Slf4jUtils.installSLF4JBridge();
Options options = constructOptions();
Options helpOptions = constructHelpOptions();
CommandLineParser parser = new DefaultParser();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.apache.commons.cli.ParseException;
import org.apache.heron.api.exception.InvalidTopologyException;
import org.apache.heron.api.generated.TopologyAPI;
import org.apache.heron.api.utils.Slf4jUtils;
import org.apache.heron.api.utils.TopologyUtils;
import org.apache.heron.common.basics.FileUtils;
import org.apache.heron.common.basics.SysUtils;
Expand Down Expand Up @@ -177,7 +178,7 @@ private static Options constructHelpOptions() {
}

public static void main(String[] args) throws Exception {

Slf4jUtils.installSLF4JBridge();
// construct the options and help options first.
Options options = constructOptions();
Options helpOptions = constructHelpOptions();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.apache.heron.api.generated.TopologyAPI;
import org.apache.heron.api.utils.Slf4jUtils;
import org.apache.heron.api.utils.TopologyUtils;
import org.apache.heron.common.basics.DryRunFormatType;
import org.apache.heron.common.basics.SysUtils;
Expand Down Expand Up @@ -297,6 +298,7 @@ dryRunFormat, isVerbose(cmd), isVerboseGC(cmd)))
}

public static void main(String[] args) throws Exception {
Slf4jUtils.installSLF4JBridge();
Options options = constructOptions();
Options helpOptions = constructHelpOptions();
CommandLineParser parser = new DefaultParser();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.google.protobuf.Message;

import org.apache.heron.api.generated.TopologyAPI;
import org.apache.heron.api.utils.Slf4jUtils;
import org.apache.heron.common.basics.FileUtils;
import org.apache.heron.proto.ckptmgr.CheckpointManager;
import org.apache.heron.proto.scheduler.Scheduler;
Expand Down Expand Up @@ -247,6 +248,7 @@ public void close() {

public static void main(String[] args) throws ExecutionException, InterruptedException,
IllegalAccessException, ClassNotFoundException, InstantiationException {
Slf4jUtils.installSLF4JBridge();
Config config = Config.newBuilder()
.put(Key.STATEMGR_ROOT_PATH,
System.getProperty("user.home") + "/.herondata/repository/state/local")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.apache.curator.framework.state.ConnectionStateListener;
import org.apache.curator.retry.ExponentialBackoffRetry;
import org.apache.heron.api.generated.TopologyAPI;
import org.apache.heron.api.utils.Slf4jUtils;
import org.apache.heron.common.basics.Pair;
import org.apache.heron.proto.ckptmgr.CheckpointManager;
import org.apache.heron.proto.scheduler.Scheduler;
Expand Down Expand Up @@ -451,7 +452,7 @@ public static void main(String[] args) throws ExecutionException, InterruptedExc
if (args.length < 2) {
throw new RuntimeException("Expects 2 arguments: <topology_name> <zookeeper_hostname>");
}

Slf4jUtils.installSLF4JBridge();
String zookeeperHostname = args[1];
Config config = Config.newBuilder()
.put(Key.STATEMGR_ROOT_PATH, "/storm/heron/states")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.apache.heron.api.utils.Slf4jUtils;
import org.apache.heron.apiserver.resources.HeronResource;
import org.apache.heron.apiserver.utils.ConfigUtils;
import org.apache.heron.apiserver.utils.Logging;
Expand Down Expand Up @@ -245,6 +246,7 @@ private static Boolean isVerbose(CommandLine cmd) {

@SuppressWarnings({"IllegalCatch", "RegexpSinglelineJava"})
public static void main(String[] args) throws Exception {
Slf4jUtils.installSLF4JBridge();
final Options options = createOptions();
final Options helpOptions = constructHelpOptions();

Expand Down
12 changes: 6 additions & 6 deletions third_party/java/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ java_library(
"@maven//:com_fasterxml_jackson_core_jackson_core",
"@maven//:com_fasterxml_jackson_core_jackson_databind",
"@maven//:commons_codec_commons_codec",
"@maven//:org_slf4j_jcl_over_slf4j",
"@maven//:org_apache_httpcomponents_httpclient",
"@maven//:org_apache_httpcomponents_httpcore",
"@maven//:org_slf4j_jcl_over_slf4j",
],
)

Expand Down Expand Up @@ -211,9 +211,9 @@ java_library(
"@maven//:com_google_http_client_google_http_client_jackson2",
"@maven//:com_google_oauth_client_google_oauth_client",
"@maven//:commons_codec_commons_codec",
"@maven//:org_slf4j_jcl_over_slf4j",
"@maven//:org_apache_httpcomponents_httpclient",
"@maven//:org_apache_httpcomponents_httpcore",
"@maven//:org_slf4j_jcl_over_slf4j",
],
)

Expand Down Expand Up @@ -351,15 +351,15 @@ java_library(
"@maven//:org_apache_distributedlog_distributedlog_protocol",
],
deps = [
"@maven//:org_slf4j_slf4j_api",
"@maven//:org_slf4j_jul_to_slf4j",
"@maven//:org_slf4j_log4j_over_slf4j",
"@maven//:org_slf4j_jcl_over_slf4j",
"@maven//:commons_collections_commons_collections",
"@maven//:commons_configuration_commons_configuration",
"@maven//:commons_lang_commons_lang",
"@maven//:io_netty_netty_all",
"@maven//:org_apache_distributedlog_distributedlog_core",
"@maven//:org_apache_distributedlog_distributedlog_protocol",
"@maven//:org_slf4j_jcl_over_slf4j",
"@maven//:org_slf4j_jul_to_slf4j",
"@maven//:org_slf4j_log4j_over_slf4j",
"@maven//:org_slf4j_slf4j_api",
],
)
2 changes: 1 addition & 1 deletion third_party/java/logback.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<configuration>
<configuration debug="false">
<shutdownHook class="ch.qos.logback.core.hook.DelayingShutdownHook" />

<contextListener class="ch.qos.logback.classic.jul.LevelChangePropagator">
Expand Down
1 change: 1 addition & 0 deletions tools/java/src/org/apache/bazel/checkstyle/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ common_deps = [
"@maven//:com_google_guava_guava",
"//third_party/java/bazel:extra_actions_proto_java",
"//third_party/java/bazel:proto_java",
"//third_party/java:logging",
]

java_binary(
Expand Down