logback-android icon indicating copy to clipboard operation
logback-android copied to clipboard

NetworkOnMainThreadException when SocketAppender host is a domain name

Open tjanson opened this issue 9 years ago • 5 comments

I’m successfully using a SocketAppender to log to a remote server when the host is set as an IP address. However, when specifying a domain name as host (otherwise identical configuration), I get a NetworkOnMainThreadExcept during startup. Possible problem: The “Lazy” setting does not seem to work.

The configuration file (and in fact the entire project) is here on Github; Log showing the exception, excerpt:

03-14 23:21:13.927 32036-32036/com.tomjanson.wifilocationlogger I/System.outďą• 23:21:13,927 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.classic.net.SocketAppender]
03-14 23:21:13.930 32036-32036/com.tomjanson.wifilocationlogger I/System.outďą• 23:21:13,930 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [SOCKET]
03-14 23:21:13.938 32036-32036/com.tomjanson.wifilocationlogger I/System.outďą• 23:21:13,938 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@57:15 - no applicable action for [lazy], current ElementPath is [[configuration][appender][lazy]]
03-14 23:21:13.967 32036-32036/com.tomjanson.wifilocationlogger I/System.outďą• 23:21:13,965 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@63:16 - RuntimeException in Action for tag [appender] android.os.NetworkOnMainThreadException

tjanson avatar Mar 14 '15 22:03 tjanson

Same problem. Did you figure out the solution?

gauravdott avatar Mar 26 '15 22:03 gauravdott

I worked around it by simply entering my server’s (thankfully static) IP address.

tjanson avatar Mar 26 '15 22:03 tjanson

ok, that's not an option for me. Thanks for reply anyway

gauravdott avatar Mar 26 '15 22:03 gauravdott

@gauravdott, Indeed, the lazy flag was unintentionally removed during a merge from the main logback project that completely rewrote the SocketAppender. I started to restore that feature in a branch.

I think this issue is actually a duplicate of #65.

tony19 avatar Dec 11 '15 00:12 tony19

A possible workaround is to use AsyncAppender as seen with this SocketAppender example. Let me know if that helps.

tony19 avatar Dec 11 '15 00:12 tony19

Closing this stale issue, as there's workaround in place (see previous comment). Please create a new issue if the issue resurfaces.

tony19 avatar Nov 06 '22 04:11 tony19