logback-android
logback-android copied to clipboard
NetworkOnMainThreadException when SocketAppender host is a domain name
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
Same problem. Did you figure out the solution?
I worked around it by simply entering my server’s (thankfully static) IP address.
ok, that's not an option for me. Thanks for reply anyway
@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.
A possible workaround is to use AsyncAppender
as seen with this SocketAppender
example. Let me know if that helps.
Closing this stale issue, as there's workaround in place (see previous comment). Please create a new issue if the issue resurfaces.