Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strictmode using syslog #14

Closed
andpro opened this issue Jul 21, 2012 · 7 comments
Closed

Strictmode using syslog #14

andpro opened this issue Jul 21, 2012 · 7 comments
Labels

Comments

@andpro
Copy link

andpro commented Jul 21, 2012

Does syslog work ok with strict mode. I got this mesg when creating the logger. But no mesg when the mesg is send.
Not done extensive testing so asking if someone has experience with it.
Thanks

D/StrictMode( 3942): at com.syslog.logback.SyslogLogbackActivity.onCreate(SyslogLogbackActivity.java:26)
D/StrictMode( 3942): at com.syslog.logback.SyslogLogbackActivity.onCreate(SyslogLogbackActivity.java:26)
D/StrictMode( 3942): at com.syslog.logback.SyslogLogbackActivity.onCreate(SyslogLogbackActivity.java:26)
D/StrictMode( 3942): at com.syslog.logback.SyslogLogbackActivity.onCreate(SyslogLogbackActivity.java:26)
D/StrictMode( 3942): at com.syslog.logback.SyslogLogbackActivity.onCreate(SyslogLogbackActivity.java:26)
D/StrictMode( 3942): at com.syslog.logback.SyslogLogbackActivity.onCreate(SyslogLogbackActivity.java:26)
D/StrictMode( 3942): at com.syslog.logback.SyslogLogbackActivity.onCreate(SyslogLogbackActivity.java:26)
D/StrictMode( 3942): at com.syslog.logback.SyslogLogbackActivity.onCreate(SyslogLogbackActivity.java:26)
D/StrictMode( 3942): at com.syslog.logback.SyslogLogbackActivity.onCreate(SyslogLogbackActivity.java:26)

@tony19
Copy link
Owner

tony19 commented Jul 21, 2012

It looks like the SyslogAppender in Android's strict mode causes a NetworkOnMainThreadException:

I/System.out( 2859): 18:07:18,030 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@0:0 - RuntimeException in Action for tag [appender] android.os.NetworkOnMainThreadException
I/System.out( 2859):    at android.os.NetworkOnMainThreadException
I/System.out( 2859):    at  at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1117)
I/System.out( 2859):    at  at java.net.InetAddress.lookupHostByName(InetAddress.java:385)
I/System.out( 2859):    at  at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
I/System.out( 2859):    at  at java.net.InetAddress.getByName(InetAddress.java:289)
I/System.out( 2859):    at  at ch.qos.logback.core.net.SyslogOutputStream.(Unknown Source)
I/System.out( 2859):    at  at ch.qos.logback.core.net.SyslogAppenderBase.start(Unknown Source)
I/System.out( 2859):    at  at ch.qos.logback.classic.net.SyslogAppender.start(Unknown Source)
I/System.out( 2859):    at  at ch.qos.logback.core.joran.action.AppenderAction.end(Unknown Source)
I/System.out( 2859):    at  at ch.qos.logback.core.joran.spi.Interpreter.callEndAction(Unknown Source)
I/System.out( 2859):    at  at ch.qos.logback.core.joran.spi.Interpreter.endElement(Unknown Source)
I/System.out( 2859):    at  at ch.qos.logback.core.joran.spi.Interpreter.endElement(Unknown Source)
I/System.out( 2859):    at  at ch.qos.logback.core.joran.spi.EventPlayer.play(Unknown Source)
I/System.out( 2859):    at  at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(Unknown Source)
I/System.out( 2859):    at  at ch.qos.logback.classic.util.ContextInitializer.configureByManifest(Unknown Source)
I/System.out( 2859):    at  at ch.qos.logback.classic.util.ContextInitializer.autoConfig(Unknown Source)
I/System.out( 2859):    at  at org.slf4j.impl.StaticLoggerBinder.init(Unknown Source)
I/System.out( 2859):    at  at org.slf4j.impl.StaticLoggerBinder.(Unknown Source)
I/System.out( 2859):    at  at org.slf4j.LoggerFactory.bind(LoggerFactory.java:128)
I/System.out( 2859):    at  at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:108)
I/System.out( 2859):    at  at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:279)
I/System.out( 2859):    at  at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:252)
I/System.out( 2859):    at  at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:265)
I/System.out( 2859):    at  at com.example.helloandroid.ItemListActivity.(ItemListActivity.java:16)
I/System.out( 2859):    at  at java.lang.Class.newInstanceImpl(Native Method)
I/System.out( 2859):    at  at java.lang.Class.newInstance(Class.java:1319)
I/System.out( 2859):    at  at android.app.Instrumentation.newActivity(Instrumentation.java:1053)
I/System.out( 2859):    at  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1974)
I/System.out( 2859):    at  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
I/System.out( 2859):    at  at android.app.ActivityThread.access$600(ActivityThread.java:130)
I/System.out( 2859):    at  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
I/System.out( 2859):    at  at android.os.Handler.dispatchMessage(Handler.java:99)
I/System.out( 2859):    at  at android.os.Looper.loop(Looper.java:137)
I/System.out( 2859):    at  at android.app.ActivityThread.main(ActivityThread.java:4745)
I/System.out( 2859):    at  at java.lang.reflect.Method.invokeNative(Native Method)
I/System.out( 2859):    at  at java.lang.reflect.Method.invoke(Method.java:511)
I/System.out( 2859):    at  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
I/System.out( 2859):    at  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
I/System.out( 2859):    at  at dalvik.system.NativeStart.main(Native Method)

@andpro
Copy link
Author

andpro commented Jul 21, 2012

Can this be fixed?

Thanks

@tony19
Copy link
Owner

tony19 commented Jul 22, 2012

Please test this snapshot of logback-android-1.0.6-2. Thanks.

@andpro
Copy link
Author

andpro commented Jul 22, 2012

Hi,

I double checked my test and looks like I do not get the Network exception as you do. The server does show the log mesg so the syslog did push the log mesg to server.
I only get violation for disk read at start up which may be ok as it is reading the configuration file.
I also checked with the snapshot and I get the same. Here is my code.

StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
.detectDiskReads().detectDiskWrites().detectNetwork()
.penaltyLog().build());
StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
.detectLeakedSqlLiteObjects().detectLeakedClosableObjects()
.penaltyLog().build());

    super.onCreate(savedInstanceState);
    logger = LoggerFactory.getLogger(SyslogLogbackActivity.class);
    LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
    StatusPrinter.print(lc);
    setContentView(R.layout.main);
    logger.debug("Hello Test Strict Mode");

config file (space added around >< as the comments is not showing properly.

< configuration debug="true" >
< appender name="SYSLOG" class="ch.qos.logback.classic.net.SyslogAppender" >
< syslogHost>AAA.REMOVED.com
< port>11111
< facility>AUTH
< suffixPattern>[%thread] %logger %msg
</ appender >
< root level="DEBUG" >
< appender-ref ref="SYSLOG" />
</ root >
</ configuration >

@andpro
Copy link
Author

andpro commented Jul 22, 2012

Hi,

In the snapshot the syslog does not work. Went back to the last released jar and it works fine on it.
Thanks

@tony19
Copy link
Owner

tony19 commented Jul 22, 2012

Ok, thanks for testing.

@tony19 tony19 closed this as completed Jul 22, 2012
@lock
Copy link

lock bot commented Feb 27, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot added the archived label Feb 27, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Feb 27, 2019
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants