Remove LogLevelAdjuster from GuiceRunnable (#4236)

* Redundant since log4j2 allows config on the fly via jmx
* Fix #1805
This commit is contained in:
Charles Allen 2017-06-28 11:06:34 -07:00 committed by Roman Leventov
parent 4c33d0a00f
commit 2fe55d30c5
3 changed files with 0 additions and 102 deletions

View File

@ -27,7 +27,6 @@ import com.google.inject.Injector;
import com.google.inject.Module; import com.google.inject.Module;
import io.druid.initialization.Initialization; import io.druid.initialization.Initialization;
import io.druid.initialization.LogLevelAdjuster;
import io.druid.java.util.common.lifecycle.Lifecycle; import io.druid.java.util.common.lifecycle.Lifecycle;
import io.druid.java.util.common.logger.Logger; import io.druid.java.util.common.logger.Logger;
import io.druid.server.log.StartupLoggingConfig; import io.druid.server.log.StartupLoggingConfig;
@ -72,7 +71,6 @@ public abstract class GuiceRunnable implements Runnable
public Lifecycle initLifecycle(Injector injector) public Lifecycle initLifecycle(Injector injector)
{ {
try { try {
LogLevelAdjuster.register();
final Lifecycle lifecycle = injector.getInstance(Lifecycle.class); final Lifecycle lifecycle = injector.getInstance(Lifecycle.class);
final StartupLoggingConfig startupLoggingConfig = injector.getInstance(StartupLoggingConfig.class); final StartupLoggingConfig startupLoggingConfig = injector.getInstance(StartupLoggingConfig.class);

View File

@ -1,72 +0,0 @@
/*
* Licensed to Metamarkets Group Inc. (Metamarkets) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. Metamarkets 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 io.druid.initialization;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import javax.management.ObjectName;
import java.lang.management.ManagementFactory;
/**
*/
public class LogLevelAdjuster implements LogLevelAdjusterMBean
{
private static final Logger log = Logger.getLogger(LogLevelAdjuster.class);
private static volatile boolean registered = false;
public synchronized static void register() throws Exception
{
if (! registered) {
ManagementFactory.getPlatformMBeanServer().registerMBean(
new LogLevelAdjuster(),
new ObjectName("log4j:name=log4j")
);
registered = true;
}
}
@Override
public String getLevel(String packageName)
{
final Level level = Logger.getLogger(packageName).getEffectiveLevel();
if (log.isInfoEnabled()) {
log.info(String.format("Asked to look up level for package[%s] => [%s]", packageName, level));
}
return level.toString();
}
@Override
public void setLevel(String packageName, String level)
{
final Level theLevel = Level.toLevel(level, null);
if (theLevel == null) {
throw new IllegalArgumentException("Unknown level: " + level);
}
if (log.isInfoEnabled()) {
log.info(String.format("Setting log level for package[%s] => [%s]", packageName, theLevel));
}
Logger.getLogger(packageName).setLevel(theLevel);
}
}

View File

@ -1,28 +0,0 @@
/*
* Licensed to Metamarkets Group Inc. (Metamarkets) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. Metamarkets 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 io.druid.initialization;
/**
*/
public interface LogLevelAdjusterMBean
{
public String getLevel(String packageName);
public void setLevel(String packageName, String level);
}