Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Jboss already comes with log4j. When developing your EJB you need to:</p> <ol> <li>import the Logger class: <code>import org.apache.log4j.Logger;</code> </li> <li>If the import does not resolve, add this jar to the path: %JBOSS_HOME%\modules\org\apache\log4j\main\log4j-1.2.16.jar</li> <li>create a field with the logger: <code>private static Logger logger = Logger.getLogger(YourEJBClass.class);</code></li> <li>use the logger in any method: <code>logger.info("my log");</code></li> </ol> <p>JBoss already comes with a configuration file under <code>%JBOSS_FOLDER%/standalone/configuration/standalone.xml</code>. By default, your logger will output to server.log and console, but you can add some appender to output your app logs to another file. </p> <p>Here is an example, edit that file and add the following snippets (following the definition of the file):</p> <ul> <li>this one is to add an appender to the file myappfile.log inside the logs folder (add this right after the already defined under name="FILE"):</li> </ul> <blockquote> <pre><code>&lt;periodic-rotating-file-handler name="FILETWO"&gt; &lt;formatter&gt; &lt;pattern-formatter pattern="%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/&gt; &lt;/formatter&gt; &lt;file relative-to="jboss.server.log.dir" path="myappfile.log"/&gt; &lt;suffix value=".yyyy-MM-dd"/&gt; &lt;append value="true"/&gt; &lt;/periodic-rotating-file-handler&gt; </code></pre> </blockquote> <ul> <li>add this snippet tells log4j to send all logs from "com.mypackage" category to the previously created appender (copy this right after other defined logger in the file, but before the root-logger):</li> </ul> <blockquote> <pre><code>&lt;logger category="com.mypackage"&gt; &lt;level name="DEBUG"/&gt; &lt;handlers&gt; &lt;handler name="CONSOLE"/&gt; &lt;handler name="FILETWO"/&gt; &lt;/handlers&gt; &lt;/logger&gt; </code></pre> </blockquote> <p>Restart the server and you should see the new myappfile.log in the folder. Make sure your app logs something, for example, adding logger.info("my servlet info log") in some servlet and call it from the browser. You'll also see this log in the console</p> <p>If you need further customization, have a look at log4j help.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload