1 2 Previous Next 16 Replies Latest reply on Jun 20, 2012 11:42 AM by wdfink

    How to enable STDOUT in JBOSS AS 5.1

    javalover_yao

      Dear, All

       

      My app is running under JBOSS AS 5.1, and there are some test code like "System.out.println('bla-bla')", but when the app runs, the eclipse console cannot show any of the system.out  information. pls help me to solve this problem.

       

      Thx

        • 1. Re: How to enable STDOUT in JBOSS AS 5.1
          peterj

          The logging system in JBoss AS is configured such that stdout and stderr are captured by the logging system and output as part of the log file. As long as you have the console log turned on in JBoss AS, then you should see those printlns.

          • 2. Re: How to enable STDOUT in JBOSS AS 5.1
            javalover_yao

            But I want to know how to turned on in JBOSS AS ? To modify the jboss-log4j.xml? if so, how to modfiy the configure file?

            • 3. Re: How to enable STDOUT in JBOSS AS 5.1
              peterj

              Have you changed the jboss-log4j.xml file? By default, the console log is on. Here is an example of what I see in the log when some code write to stdout:

               

              2011-04-16 15:28:09,420 INFO  [STDOUT] (Thread-1) Posting Shutdown Request to the server...

              • 4. Re: How to enable STDOUT in JBOSS AS 5.1
                vaedama

                Jason,

                Go to directory : ...\jboss 5.1.0\jboss-5.1.0.GA\server\default\conf and edit your jboss-log4j.xml file.

                 

                I believe, by default STDOUT and STDERR are enabled.

                 

                If you want to enable logging using log4j then go and edit your joboss-log4j.xml file. As an example:

                 

                <!-- =================== -->

                   <!-- Project Name       -->

                   <!-- =================== -->

                   <appender name="ProjectLogFile" class="org.jboss.logging.appender.RollingFileAppender">

                     <errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>

                     <param name="File"           value="${jboss.server.log.dir}/projectName.log"/>

                     <param name="Append"         value="false"/>

                     <param name="MaxFileSize"    value="500KB"/>

                     <param name="MaxBackupIndex" value="1"/>

                 

                 

                     <layout class="org.apache.log4j.PatternLayout">

                       <param name="ConversionPattern" value="%d %-5p [%c] %m%n"/>

                     </layout>             

                   </appender>

                 

                 

                   <category name="com.company.project.module.Class" additivity="false">

                     <priority value="DEBUG"/>

                     <appender-ref ref="LogFile"/>

                   </category>

                 

                 

                you can set the priority value as you want.. I set is as DEBUG here.

                 

                you can add as many classes as you want to log under this Project.

                 

                That means you can have logging for as many projects as you want by editing the jboss-log4j.xml file.

                • 5. Re: How to enable STDOUT in JBOSS AS 5.1
                  javalover_yao

                  Actually,I do not change the configure file, I use the default configuration. The console log of my jboss as 5.1 seems is disabled, it can print the log information, but cannot print the PRINTLNS information. any suggestion?

                  The following is my jboss-log4j.xml :

                   

                  <?xml version="1.0" encoding="UTF-8"?>

                  <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">

                     <!-- ================================= -->
                     <!-- Preserve messages in a local file -->
                     <!-- ================================= -->

                     <!-- A time/date based rolling appender -->
                     <appender name="FILE" class="org.jboss.logging.appender.DailyRollingFileAppender">
                        <errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
                        <param name="File" value="${jboss.server.log.dir}/server.log"/>
                        <param name="Append" value="true"/>
                        <param name="DatePattern" value="'.'yyyy-MM-dd"/>
                        <layout class="org.apache.log4j.PatternLayout">
                           <param name="ConversionPattern" value="%d %-5p [%c] (%t) %m%n"/>
                        </layout>
                     </appender>


                     <!-- ============================== -->
                     <!-- Append messages to the console -->
                     <!-- ============================== -->

                     <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
                        <errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
                        <param name="Target" value="System.out"/>
                        <param name="Threshold" value="INFO"/>

                        <layout class="org.apache.log4j.PatternLayout">
                           <!-- The default pattern: Date Priority [Category] Message\n -->
                           <param name="ConversionPattern" value="%d{ABSOLUTE} %-5p [%c{1}] %m%n"/>
                        </layout>
                     </appender>

                   
                     <category name="org.apache">
                        <priority value="INFO"/>
                     </category>
                    
                     <!-- Limit the jacorb category to WARN as its INFO is verbose -->
                     <category name="jacorb">
                        <priority value="WARN"/>
                     </category>
                    

                     <category name="javax.enterprise.resource.webcontainer.jsf">
                       <priority value="INFO" class="org.jboss.logging.log4j.JDKLevel"/>
                     </category>
                    
                     <!-- Limit the org.jgroups category to WARN as its INFO is verbose -->
                     <category name="org.jgroups">
                        <priority value="WARN"/>
                     </category>
                    
                     <!-- Limit the org.quartz category to INFO as its DEBUG is verbose -->
                     <category name="org.quartz">
                        <priority value="INFO"/>
                     </category>
                    
                     <!-- Limit the com.sun category to INFO as its FINE is verbose -->
                     <category name="com.sun">
                        <priority value="INFO"/>
                     </category>
                    
                     <!-- Limit the sun category to INFO as its FINE is verbose -->
                     <category name="sun">
                        <priority value="INFO"/>
                     </category>
                    
                     <!-- Limit the javax.xml.bind category to INFO as its FINE is verbose -->
                     <category name="javax.xml.bind">
                        <priority value="INFO"/>
                     </category>


                     <!-- Limit the JSR77 categories -->
                     <category name="org.jboss.management">
                        <priority value="INFO"/>
                     </category>

                     <!-- Limit the verbose facelets compiler -->
                     <category name="facelets.compiler">
                        <priority value="WARN"/>
                     </category>
                    
                     <!-- Limit the verbose ajax4jsf cache initialization -->
                     <category name="org.ajax4jsf.cache">
                        <priority value="WARN"/>
                     </category>
                    
                     <!-- Limit the verbose embedded jopr categories -->
                     <category name="org.rhq">
                        <priority value="WARN"/>
                     </category>
                    
                     <!-- Limit the verbose seam categories -->
                     <category name="org.jboss.seam">
                        <priority value="WARN"/>
                     </category>

                    
                     <!-- Limit the org.jboss.serial (jboss-serialization) to INFO as its DEBUG is verbose -->
                     <category name="org.jboss.serial">
                        <priority value="INFO"/>
                     </category>


                     <!-- ======================= -->
                     <!-- Setup the Root category -->
                     <!-- ======================= -->

                     <root>

                        <priority value="${jboss.server.log.threshold}"/>
                        <appender-ref ref="CONSOLE"/>
                        <appender-ref ref="FILE"/>
                     </root>
                  </log4j:configuration>

                  • 6. Re: How to enable STDOUT in JBOSS AS 5.1
                    javalover_yao

                    Unfortunately, My console connot shows the [STDOUT] and [STDERR] information, which JBOSS version you use? Could you show me  the default configuration of the jboss-log4j.xml ?

                    • 7. Re: How to enable STDOUT in JBOSS AS 5.1
                      peterj

                      Check the server.log file for entries with the text "[STDOUT]". The example log entry I showed came from server.log (I didn't want to have to hunt up an app that wrote to stdout, so I just searched my server.log files for an existing entry). But since you have the console lof configured, the output should be there (text written to stdout is logged at the INFO level, as you can see from the example).

                      • 8. Re: How to enable STDOUT in JBOSS AS 5.1
                        peterj

                        Just for the fun of it, I added this line to one of my simple servlets:

                         

                          @Override

                          protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException,

                              IOException {

                            System.out.println("hello from the servlet");

                            . . .

                          }

                         

                        And here is what I saw in the console log:

                         

                        17:34:19,207 INFO  [STDOUT] hello from the servlet

                         

                        I am using the default logging configuration for JBoss AS 5.1.0.GA.

                        1 of 1 people found this helpful
                        • 9. Re: How to enable STDOUT in JBOSS AS 5.1
                          javalover_yao

                          Thank you for your reply, ive found the reason, it seems that my app's log4j is conflicted with the jboss log4j....but i still dont know how to resolve the conflict problem...jesus

                          • 10. Re: How to enable STDOUT in JBOSS AS 5.1
                            peterj

                            My app does not have a logging configuration file, nor do I package the logj4.jar file with my application.

                            • 11. Re: How to enable STDOUT in JBOSS AS 5.1
                              javalover_yao

                              If i remove the project and create a new project without log4j plugin, and then write a simple servlet, STDOUT works...

                              • 12. Re: How to enable STDOUT in JBOSS AS 5.1
                                javalover_yao

                                Dear,All

                                 

                                Ive solve the problem about my app is conflicted with the jboss's log4j configu

                                 

                                ration, I hope the following solution will help the people who mets the same problem with me :

                                 

                                To solve this problem, you should goto the directory: %JBOSS_HOME%/server/default/conf/jboss-service.xml

                                 

                                And then modify the configuration file named: jboss-service.xml

                                 

                                To find the node:

                                 

                                <mbean code="org.jboss.logging.Log4jService"
                                      name="jboss.system:type=Log4jService,service=Logging"
                                      xmbean-dd="resource:xmdesc/Log4jService-xmbean.xml">
                                      <attribute name="ConfigurationURL">resource:jboss-log4j.xml</attribute>
                                      <!-- Set the org.apache.log4j.helpers.LogLog.setQuiteMode. As of log4j1.2.8
                                      this needs to be set to avoid a possible deadlock on exception at the
                                      appender level. See bug#696819.
                                      -->
                                      <attribute name="Log4jQuietMode">true</attribute>
                                      <!-- How frequently in seconds the ConfigurationURL is checked for changes -->
                                      <attribute name="RefreshPeriod">60</attribute>
                                           <!-- The value to assign to system property jboss.server.log.threshold
                                           if it is not already set. This system property in turn controls
                                           the logging threshold for the server.log file.
                                           If the system property is already set when this service is created,
                                           this value is ignored. -->
                                      <attribute name="DefaultJBossServerLogThreshold">INFO</attribute>
                                   </mbean>

                                 

                                Add one attribute :

                                 

                                <attribute name="CatchSystemOut">false</attribute>

                                 

                                After modify the file, it will looks like below:

                                 

                                <mbean code="org.jboss.logging.Log4jService"
                                      name="jboss.system:type=Log4jService,service=Logging"
                                      xmbean-dd="resource:xmdesc/Log4jService-xmbean.xml">
                                      <attribute name="ConfigurationURL">resource:jboss-log4j.xml</attribute>
                                      <!-- Set the org.apache.log4j.helpers.LogLog.setQuiteMode. As of log4j1.2.8
                                      this needs to be set to avoid a possible deadlock on exception at the
                                      appender level. See bug#696819.
                                      -->
                                      <attribute name="Log4jQuietMode">true</attribute>
                                      <!-- How frequently in seconds the ConfigurationURL is checked for changes -->
                                      <attribute name="RefreshPeriod">60</attribute>
                                      <attribute name="CatchSystemOut">false</attribute>
                                      <!-- The value to assign to system property jboss.server.log.threshold
                                           if it is not already set. This system property in turn controls
                                           the logging threshold for the server.log file.
                                           If the system property is already set when this service is created,
                                           this value is ignored. -->
                                      <attribute name="DefaultJBossServerLogThreshold">INFO</attribute>
                                   </mbean>

                                 

                                Finally, you should restart the JBOSS server to make the change effective.

                                 

                                Thanks & Regards

                                 

                                Jason

                                 

                                • 13. Re: How to enable STDOUT in JBOSS AS 5.1
                                  refon

                                  In my experience when having trouble with logging in JBOSS-AS-5.1 you first need to check

                                  you did not include log4j jar to your project (ear, war) (it easily happens with Maven dependencies )

                                   

                                  Then you should have System.out.println("Hello");

                                  as

                                  2011-11-08 08:07:06,486 INFO  [STDOUT] (http-127.0.0.1-8080-1) Hello

                                   

                                  Patrick

                                  • 14. Re: How to enable STDOUT in JBOSS AS 5.1
                                    javalover_yao

                                    Thank you for your suggestion, and my project is used the JBOSS's log4j.jar

                                    1 2 Previous Next