From 299f78a665862ffcd13072363ea632c71313d7c7 Mon Sep 17 00:00:00 2001 From: Ian Luo Date: Thu, 3 May 2018 15:07:34 +0800 Subject: [PATCH] Merge pull request #1717, NettyHelper in netty extension populated Logger "InternalLogger" in netty. --- .../transport/netty4/NettyClient.java | 2 - .../transport/netty4/NettyServer.java | 3 - .../transport/netty4/logging/NettyHelper.java | 268 ------------------ 3 files changed, 273 deletions(-) delete mode 100644 dubbo-remoting/dubbo-remoting-netty4/src/main/java/com/alibaba/dubbo/remoting/transport/netty4/logging/NettyHelper.java diff --git a/dubbo-remoting/dubbo-remoting-netty4/src/main/java/com/alibaba/dubbo/remoting/transport/netty4/NettyClient.java b/dubbo-remoting/dubbo-remoting-netty4/src/main/java/com/alibaba/dubbo/remoting/transport/netty4/NettyClient.java index 73c54b7499a..ea273aebfae 100644 --- a/dubbo-remoting/dubbo-remoting-netty4/src/main/java/com/alibaba/dubbo/remoting/transport/netty4/NettyClient.java +++ b/dubbo-remoting/dubbo-remoting-netty4/src/main/java/com/alibaba/dubbo/remoting/transport/netty4/NettyClient.java @@ -25,7 +25,6 @@ import com.alibaba.dubbo.remoting.ChannelHandler; import com.alibaba.dubbo.remoting.RemotingException; import com.alibaba.dubbo.remoting.transport.AbstractClient; -import com.alibaba.dubbo.remoting.transport.netty4.logging.NettyHelper; import io.netty.bootstrap.Bootstrap; import io.netty.buffer.PooledByteBufAllocator; @@ -58,7 +57,6 @@ public NettyClient(final URL url, final ChannelHandler handler) throws RemotingE @Override protected void doOpen() throws Throwable { - NettyHelper.setNettyLoggerFactory(); final NettyClientHandler nettyClientHandler = new NettyClientHandler(getUrl(), this); bootstrap = new Bootstrap(); bootstrap.group(nioEventLoopGroup) diff --git a/dubbo-remoting/dubbo-remoting-netty4/src/main/java/com/alibaba/dubbo/remoting/transport/netty4/NettyServer.java b/dubbo-remoting/dubbo-remoting-netty4/src/main/java/com/alibaba/dubbo/remoting/transport/netty4/NettyServer.java index 1924bd16e80..c4ffcf5dde4 100644 --- a/dubbo-remoting/dubbo-remoting-netty4/src/main/java/com/alibaba/dubbo/remoting/transport/netty4/NettyServer.java +++ b/dubbo-remoting/dubbo-remoting-netty4/src/main/java/com/alibaba/dubbo/remoting/transport/netty4/NettyServer.java @@ -28,7 +28,6 @@ import com.alibaba.dubbo.remoting.Server; import com.alibaba.dubbo.remoting.transport.AbstractServer; import com.alibaba.dubbo.remoting.transport.dispatcher.ChannelHandlers; -import com.alibaba.dubbo.remoting.transport.netty4.logging.NettyHelper; import io.netty.bootstrap.ServerBootstrap; import io.netty.buffer.PooledByteBufAllocator; @@ -68,8 +67,6 @@ public NettyServer(URL url, ChannelHandler handler) throws RemotingException { @Override protected void doOpen() throws Throwable { - NettyHelper.setNettyLoggerFactory(); - bootstrap = new ServerBootstrap(); bossGroup = new NioEventLoopGroup(1, new DefaultThreadFactory("NettyServerBoss", true)); diff --git a/dubbo-remoting/dubbo-remoting-netty4/src/main/java/com/alibaba/dubbo/remoting/transport/netty4/logging/NettyHelper.java b/dubbo-remoting/dubbo-remoting-netty4/src/main/java/com/alibaba/dubbo/remoting/transport/netty4/logging/NettyHelper.java deleted file mode 100644 index 715aa6479dc..00000000000 --- a/dubbo-remoting/dubbo-remoting-netty4/src/main/java/com/alibaba/dubbo/remoting/transport/netty4/logging/NettyHelper.java +++ /dev/null @@ -1,268 +0,0 @@ -/* - * 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 com.alibaba.dubbo.remoting.transport.netty4.logging; - -import com.alibaba.dubbo.common.logger.Logger; -import com.alibaba.dubbo.common.logger.LoggerFactory; -import io.netty.util.internal.logging.AbstractInternalLogger; -import io.netty.util.internal.logging.InternalLogger; -import io.netty.util.internal.logging.InternalLoggerFactory; - -public class NettyHelper { - - public static void setNettyLoggerFactory() { - InternalLoggerFactory factory = InternalLoggerFactory.getDefaultFactory(); - if (factory == null || !(factory instanceof DubboLoggerFactory)) { - InternalLoggerFactory.setDefaultFactory(new DubboLoggerFactory()); - } - } - - static class DubboLoggerFactory extends InternalLoggerFactory { - - @Override - public InternalLogger newInstance(String name) { - return new DubboLogger(LoggerFactory.getLogger(name)); - } - } - - static class DubboLogger extends AbstractInternalLogger { - - private Logger logger; - - DubboLogger(Logger logger) { - super(logger.getClass().getName()); - this.logger = logger; - } - - @Override - public boolean isTraceEnabled() { - return logger.isTraceEnabled(); - } - - @Override - public void trace(String msg) { - if (isTraceEnabled()) { - logger.trace(msg); - } - } - - @Override - public void trace(String format, Object arg) { - if (isTraceEnabled()) { - FormattingTuple ft = MessageFormatter.format(format, arg); - logger.trace(ft.getMessage(), ft.getThrowable()); - } - - } - - @Override - public void trace(String format, Object argA, Object argB) { - if (isTraceEnabled()) { - FormattingTuple ft = MessageFormatter.format(format, argA, argB); - logger.trace(ft.getMessage(), ft.getThrowable()); - } - } - - @Override - public void trace(String format, Object... arguments) { - if (isTraceEnabled()) { - FormattingTuple ft = MessageFormatter.arrayFormat(format, arguments); - logger.trace(ft.getMessage(), ft.getThrowable()); - } - } - - @Override - public void trace(String msg, Throwable t) { - if (isTraceEnabled()) { - logger.trace(msg, t); - } - } - - @Override - public boolean isDebugEnabled() { - return logger.isDebugEnabled(); - } - - @Override - public void debug(String msg) { - if (isDebugEnabled()) { - logger.debug(msg); - } - } - - @Override - public void debug(String format, Object arg) { - if (isDebugEnabled()) { - FormattingTuple ft = MessageFormatter.format(format, arg); - logger.debug(ft.getMessage(), ft.getThrowable()); - } - } - - @Override - public void debug(String format, Object argA, Object argB) { - if (isDebugEnabled()) { - FormattingTuple ft = MessageFormatter.format(format, argA, argB); - logger.debug(ft.getMessage(), ft.getThrowable()); - } - } - - @Override - public void debug(String format, Object... arguments) { - if (isDebugEnabled()) { - FormattingTuple ft = MessageFormatter.arrayFormat(format, arguments); - logger.debug(ft.getMessage(), ft.getThrowable()); - } - } - - @Override - public void debug(String msg, Throwable t) { - if (isDebugEnabled()) { - logger.debug(msg, t); - } - } - - @Override - public boolean isInfoEnabled() { - return logger.isInfoEnabled(); - } - - @Override - public void info(String msg) { - if (isInfoEnabled()) { - logger.info(msg); - } - } - - @Override - public void info(String format, Object arg) { - if (isInfoEnabled()) { - FormattingTuple ft = MessageFormatter.format(format, arg); - logger.info(ft.getMessage(), ft.getThrowable()); - } - } - - @Override - public void info(String format, Object argA, Object argB) { - if (isInfoEnabled()) { - FormattingTuple ft = MessageFormatter.format(format, argA, argB); - logger.info(ft.getMessage(), ft.getThrowable()); - } - } - - @Override - public void info(String format, Object... arguments) { - if (isInfoEnabled()) { - FormattingTuple ft = MessageFormatter.arrayFormat(format, arguments); - logger.info(ft.getMessage(), ft.getThrowable()); - } - } - - @Override - public void info(String msg, Throwable t) { - if (isInfoEnabled()) { - logger.info(msg, t); - } - } - - @Override - public boolean isWarnEnabled() { - return false; - } - - @Override - public void warn(String msg) { - if (isWarnEnabled()) { - logger.warn(msg); - } - } - - @Override - public void warn(String format, Object arg) { - if (isWarnEnabled()) { - FormattingTuple ft = MessageFormatter.format(format, arg); - logger.warn(ft.getMessage(), ft.getThrowable()); - } - } - - @Override - public void warn(String format, Object... arguments) { - if (isWarnEnabled()) { - FormattingTuple ft = MessageFormatter.arrayFormat(format, arguments); - logger.warn(ft.getMessage(), ft.getThrowable()); - } - } - - @Override - public void warn(String format, Object argA, Object argB) { - if (isWarnEnabled()) { - FormattingTuple ft = MessageFormatter.format(format, argA, argB); - logger.warn(ft.getMessage(), ft.getThrowable()); - } - } - - @Override - public void warn(String msg, Throwable t) { - if (isWarnEnabled()) { - logger.warn(msg, t); - } - } - - @Override - public boolean isErrorEnabled() { - return logger.isErrorEnabled(); - } - - @Override - public void error(String msg) { - if (isErrorEnabled()) { - logger.error(msg); - } - } - - @Override - public void error(String format, Object arg) { - if (isErrorEnabled()) { - FormattingTuple ft = MessageFormatter.format(format, arg); - logger.error(ft.getMessage(), ft.getThrowable()); - } - } - - @Override - public void error(String format, Object argA, Object argB) { - if (isErrorEnabled()) { - FormattingTuple ft = MessageFormatter.format(format, argA, argB); - logger.error(ft.getMessage(), ft.getThrowable()); - } - } - - @Override - public void error(String format, Object... arguments) { - if (isErrorEnabled()) { - FormattingTuple ft = MessageFormatter.arrayFormat(format, arguments); - logger.error(ft.getMessage(), ft.getThrowable()); - } - } - - @Override - public void error(String msg, Throwable t) { - if (isErrorEnabled()) { - logger.error(msg, t); - } - } - } - -}