Skip to content

NettyHelper in netty extension populated Logger "InternalLogger" in netty. #1447

Closed

Description

@hnlxl

系统中有自己的Netty服务器,同时指定Dubbo用Netty,然后LoggingHandler就没法用了。下面的代码回导致我的Netty服务器无法使用Netty自带的日志体系。如果我强制自己的Netty服务器晚于Dubbo加载,那么Dubbo也是无法使用到DubboLogger的。

public class NettyHelper {

    public static void setNettyLoggerFactory() {
        InternalLoggerFactory factory = InternalLoggerFactory.getDefaultFactory();
        if (factory == null || !(factory instanceof DubboLoggerFactory)) {
            InternalLoggerFactory.setDefaultFactory(new DubboLoggerFactory());
        }
    }

Added content in English. Help with Google Translate

System is TCP server using Netty4, and Dubbo is specified to use Netty4. When I add LoggingHandler to ChannelPipeline of my System, The log is not expected.
Like this:
image

I tracked the code and found the Logger is com.alibaba.dubbo.remoting.transport.netty4.logging.NettyHelper.DubboLogger instead of io.netty.util.internal.logging.Slf4JLogger. DubboLogger added other content arount the original log. The NeetyHelper replace the InternalLoggerFactory when Dubbo loading, like the code block above shows.

By the way.

My system build by Spring Boot, use default logging framework which is Slf4j + Logback.
Dubbo's logger is not extend default logger, but replace it.
image

Activity

  1. chickenlj commented on Mar 11, 2018

    @chickenlj
    Contributor

    Hi,

    Please consider using English, Dubbo is a global community, and all the issues may be viewed and discussed by people all over the world.

    Can not work? Is there any detailed error recorded? I think LoggingHandler will also use the DubboLogger specified by Dubbo, and it will finally depend on the real logger implementation, e.g. log4j, slf4j, etc. If the logger is not specified by dubbo, someone else will specify it, will different specifier make any difference to you.

    Please send more details to @[email protected] for in-depth discussion.

    Thanks

  2. changed the title [-]Netty4的NettyHelper类,污染了Netty4的日志工厂[/-] [+]NettyHelper in netty extension populated Logger "InternalLogger" in netty.[/+] on Mar 11, 2018
  3. kimmking commented on Mar 11, 2018

    @kimmking
    Member

    I think you can send a mail to [email protected] about keeping default logger mechanism in netty for further discussion. @teclxl

  4. hnlxl commented on Mar 15, 2018

    @hnlxl
    Author

    Sorry, the message mail is classified by Outlook as other without push notification.

  5. hnlxl commented on Mar 15, 2018

    @hnlxl
    Author

    Press wrong button to close.

  6. reopened this on Mar 15, 2018
  7. beiwei30 commented on Apr 24, 2018

    @beiwei30
    Member

    @teclxl That's true com.alibaba.dubbo.remoting.transport.netty4.logging.NettyHelper.DubboLogger will be used if dubbo boots ahead of your netty, but if you look into com.alibaba.dubbo.common.logger.LoggerFactory, you will find DubboLogger will eventually delegate to the real logging framework your app relies on:

        // search common-used logging frameworks
        static {
            String logger = System.getProperty("dubbo.application.logger");
            if ("slf4j".equals(logger)) {
                setLoggerAdapter(new Slf4jLoggerAdapter());
            } else if ("jcl".equals(logger)) {
                setLoggerAdapter(new JclLoggerAdapter());
            } else if ("log4j".equals(logger)) {
                setLoggerAdapter(new Log4jLoggerAdapter());
            } else if ("jdk".equals(logger)) {
                setLoggerAdapter(new JdkLoggerAdapter());
            } else {
                try {
                    setLoggerAdapter(new Log4jLoggerAdapter());
                } catch (Throwable e1) {
                    try {
                        setLoggerAdapter(new Slf4jLoggerAdapter());
                    } catch (Throwable e2) {
                        try {
                            setLoggerAdapter(new JclLoggerAdapter());
                        } catch (Throwable e3) {
                            setLoggerAdapter(new JdkLoggerAdapter());
                        }
                    }
                }
            }
        }

    I am not sure if it satisfies what you demands. In order to help clarify this issue better, I push a same code at https://github.com/beiwei30/netty-dubbo-logging-test, pls. modify it further in order to help me understand your issue better.

  8. chickenlj commented on Apr 25, 2018

    @chickenlj
    Contributor

    I think beiwei30 and me both have clarified this issue. It shouldn't be caused by dubbo's NettyHelper.

  9. beiwei30 commented on Apr 26, 2018

    @beiwei30
    Member
  10. added this to the 2.6.3 milestone on Apr 26, 2018
  11. hnlxl commented on May 4, 2018

    @hnlxl
    Author

    @beiwei30 I think your change can solve this issue. I think the reason is that FailsafeLogger changed all msg, too.
    I saw you have already begun to slove this issue. I don't know if it is appropriate to close the issue now. Please close this issue, if you think it is appropriate.

  12. ralf0131 commented on May 15, 2018

    @ralf0131
    Contributor

    @beiwei30 Can this issue be closed?

  13. ralf0131 commented on Jul 20, 2018

    @ralf0131
    Contributor

    This issue has been fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions