<div dir="ltr">I&#39;ve copied James Perkins, who is the WildFly logging component lead.</div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr">Brian Stansberry<div>Manager, Senior Principal Software Engineer</div><div>Red Hat</div></div></div></div>
<br><div class="gmail_quote">On Fri, Sep 29, 2017 at 3:35 AM, Thomas Heute <span dir="ltr">&lt;<a href="mailto:theute@redhat.com" target="_blank">theute@redhat.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Adding Dimitris and Brian (It relates to <a href="https://issues.jboss.org/browse/WFCORE-2526" target="_blank">https://issues.jboss.org/<wbr>browse/WFCORE-2526</a> )<div><br></div><div>(Mazz I have a question below)<br><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Sep 28, 2017 at 5:29 PM, John Mazzitelli <span dir="ltr">&lt;<a href="mailto:mazz@redhat.com" target="_blank">mazz@redhat.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">&lt;tl;dr&gt;<br>
No matter if a java agent uses JBoss Logging or simply relies on the JRE&#39;s own Java logging, it still won&#39;t work in WildFly/EAP unless you set additional things to environment variables in standalone.conf. So no matter what logging is used, this means problems still need to be overcome when putting java agents in host controllers for EAP 7.0 domain mode.<br>
&lt;/tl;dr&gt;<br>
<br>
I am looking at how Java Agents should log messages when attached to WildFly or EAP. I want to see if there is a way to implement a Java Agent and NOT have to set any special JAVA_OPTS values to pass to the VM to get it to work.<br>
<br>
Turns out, it is not a trivial issue.<br>
<br>
I wrote a silly little test agent [1] just to see what would happen if it simply logs a message using *java* logging and spins a thread logging a message every second again using *java* logging. So, no extra third party logging libraries, just using java.util.logging classes that are in the JRE already.<br>
<br>
Adding just -javaagent to JAVA_OPTS (in standalone.conf, add something like &quot;-javaagent:/where/it/is/ja.ja<wbr>r=foo=bar&quot;) is no good, the server bombs with this error, presumably because my agent already started logging using java logger:<br>
<br>
   Caused by: java.util.concurrent.Execution<wbr>Exception: java.lang.IllegalStateExceptio<wbr>n: WFLYLOG0078: The logging subsystem requires the log manager to be org.jboss.logmanager.LogManage<wbr>r. The subsystem has not be initialized and cannot be used. To use JBoss Log Manager you must add the system property &quot;java.util.logging.manager&quot; and set it to &quot;org.jboss.logmanager.LogManag<wbr>er&quot;<br>
<br>
Well, catch-22, because if I set java.util.logging.manager=org.<wbr>jboss.logmanager.LogManager in JAVA_OPTS, this happens when the test agent tries to log:<br>
<br>
   Could not load Logmanager &quot;org.jboss.logmanager.LogManag<wbr>er&quot;<br>
   java.lang.ClassNotFoundExcept<wbr>ion: org.jboss.logmanager.LogManage<wbr>r<br>
<br>
which then falls back to java logging, which then causes the server to bomb again because it wants JBoss Logging.<br>
<br>
If I set this in standalone.conf:<br>
<br>
   JBOSS_MODULES_SYSTEM_PKGS=&quot;or<wbr>g.jboss.byteman,org.jboss.logm<wbr>anager&quot;<br>
<br>
the java agent still gets this error:<br>
<br>
   Could not load Logmanager &quot;org.jboss.logmanager.LogManag<wbr>er&quot;<br>
   java.lang.ClassNotFoundExcept<wbr>ion: org.jboss.logmanager.LogManage<wbr>r<br>
<br>
which is then followed by jboss modules error which causes the server to again to fail to start:<br>
<br>
   WARNING: Failed to load the specified log manager class org.jboss.logmanager.LogManage<wbr>r<br>
   Exception in thread &quot;main&quot; java.lang.NoClassDefFoundError<wbr>: org/jboss/logmanager/Level<br>
      ...<br>
        at org.jboss.modules.Module.run(M<wbr>odule.java:320)<br>
<br>
The ONLY way to get the server to start properly with this java agent installed (EVEN WITH the agent using ONLY java logging), you have to do all of the above plus add this to JAVA_OPTS:<br>
<br>
-Xbootclasspath/p:$JBOSS_HOME/<wbr>modules/system/layers/base/org<wbr>/jboss/logmanager/main/jboss-<wbr>logmanager-2.0.4.Final.jar<br>
<br>
So, in short, you need to add &quot;-Djava.util.logging.manager=o<wbr>rg.jboss.logmanager.LogManager<wbr>&quot; to JAVA_OPTS, you need to add &quot;,org.jboss.logmanager&quot; to JBOSS_MODULES_SYSTEM_PKGS, and you need to add that -Xbootclasspath to JAVA_OPTS just to get a javaagent to work even if the javaagent simply uses nothing more than standard java logging.<br></blockquote><div><br></div><div>That&#39;s for WF-Core 2.x (as in EAP 7.0), how about WF-Core 3 (as in EAP 7.1) ? IIRC you also need some of those ugliness ?</div><div><br></div><div>Thomas</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
---<br>
<br>
[1] $ cat JavaAgent.java<br>
import java.util.logging.*;<br>
public class JavaAgent {<br>
    private static final Logger log = Logger.getLogger(JavaAgent.cla<wbr>ss.getName());<br>
    public static void premain(String args) {<br>
        log.severe(&quot;log in premain: &quot; + args);<br>
        new Thread(new Runnable() {<br>
            public void run() {<br>
                while (true) {<br>
                    try {<br>
                        Thread.sleep(1000);<br>
                        log.severe(&quot;log in premain loop: &quot; + args);<br>
                    } catch (Exception e) {<br>
                        return;<br>
                    }<br>
                }<br>
            }<br>
        }).start();<br>
    }<br>
}<br>
<br>
To build it:<br>
<br>
$ echo &quot;Premain-Class: JavaAgent&quot; &gt; manifest.mf<br>
$ javac JavaAgent.java<br>
$ jar cvfm ja.jar manifest.mf JavaAgent*<br>
<br>
______________________________<wbr>_________________<br>
hawkular-dev mailing list<br>
<a href="mailto:hawkular-dev@lists.jboss.org" target="_blank">hawkular-dev@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/hawkular-dev" rel="noreferrer" target="_blank">https://lists.jboss.org/mailma<wbr>n/listinfo/hawkular-dev</a><br>
</blockquote></div><br></div></div></div>
</blockquote></div><br></div>