如何更改外部jar中类的调试级别

时间:2016-12-27 09:11:02

标签: java logging log4j

我需要更改外部jar文件中类的日志记录级别。在jar中的那个类中,代码如下所示。我需要做的只是实际更改日志记录级别。

myDbContext.ModelView

所以我想将日志级别更改为调试,如何才能为jar文件这样做呢?

1 个答案:

答案 0 :(得分:1)

使用Below方法检查应用程序是否包含debug true / false

    private static final X500Principal DEBUG_DN = new X500Principal("CN=Android Debug,O=Android,C=US");
    private boolean isDebuggable(Context ctx)
    {
        boolean debuggable = false;
        try
        {
            PackageInfo pinfo = ctx.getPackageManager().getPackageInfo(ctx.getPackageName(),PackageManager.GET_SIGNATURES);
            Signature signatures[] = pinfo.signatures;

            CertificateFactory cf = CertificateFactory.getInstance("X.509");

            for ( int i = 0; i < signatures.length;i++)
            {
                ByteArrayInputStream stream = new ByteArrayInputStream(signatures[i].toByteArray());
                X509Certificate cert = (X509Certificate) cf.generateCertificate(stream);
                debuggable = cert.getSubjectX500Principal().equals(DEBUG_DN);
                if (debuggable)
                    break;
            }
        }
        catch (NameNotFoundException e)
        {
            //debuggable variable will remain false
        }
        catch (CertificateException e)
        {
            //debuggable variable will remain false
        }
        return debuggable;
    }