Hot questions for Using GlassFish in log4j


sql_show = true

this property in hibernate prints the sql that is run, but i want to see the begin transaction and complete transaction statements as well so that i can track the transaction duration and see the query run in which transaction.

googling reveals that = DEBUG, defaultAppender = DEBUG, defaultAppender, defaultAppender

should show you the transaction level data as well. But it doesnt.

Investigating more i looked into hibernate code and found a class name


this class has the begin and complete method but this method does not log any thing.

Any advice how to see the transaction level info in hibernate ? I am using hibernate 2.2


For Hibernate 5
  • For SLF4J logging:

    <logger name="org.hibernate.engine.transaction.internal.TransactionImpl" level="debug"/>
  • For Log4j:

     <logger name="org.hibernate.engine.transaction.internal.TransactionImpl">
          <level value="DEBUG"/>
For Hibernate 4

You need to set the logging threshold to DEBUG for the following classes:

  1. For JDBC transactions (e.g. RESOURCE_LOCAL)

    • For SLF4J logging:

      <logger name="org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction" level="debug"/>
    • For Log4j:

      <logger name="org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction">
         <level value="DEBUG"/>
  2. For JTA transactions

    • For SLF4J logging:

      <logger name="org.hibernate.engine.transaction.internal.jta.JtaTransaction" level="debug"/>
    • For Log4j:

      <logger name="org.hibernate.engine.transaction.internal.jta.JtaTransaction">
         <level value="DEBUG"/>

It's better to activate the DEBUG level for as few classes as possible because otherwise, your logs size will increase dramatically.


I have many applications (war, ejb) in same glassfish server, the applications have different log4j configuration

app1.war ->

log4j.rootLogger=info, infcore
log4j.appender.infcore.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} [%5p] [%t] %c %x - %m%n

app2.jar ->

log4j.rootLogger=info, infoejb
log4j.appender.infoejb.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} [%5p] [%t] %c %x - %m%n

app3.war ->

log4j.rootLogger=info, infoapp2
log4j.appender.infoapp2.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} [%5p] [%t] %c %x - %m%n

I call logger:

protected static final Logger LOG = Logger.getLogger(JAXSecurutyValidation.class);

The problem is that the information is recorded in only one file the ejb, the others files are not created.

How can I fix it?

SOLVED I find the solution, is very simple update to glasfish 5 and all works fine, thanks.


Maybe this can help you:

String log4jfile = "log4 file path";

You can call each log4j file for each application.


I am using Payara 4.1 and Netbeans 8.1.

When I run my application, these four lines are among the first to be logged:

 #!## LogManagerService.postConstruct : rootFolder=/opt/payara41/glassfish
 #!## LogManagerService.postConstruct : templateDir=/opt/payara41/glassfish/lib/templates
 #!## LogManagerService.postConstruct : src=/opt/payara41/glassfish/lib/templates/
 #!## LogManagerService.postConstruct : dest=/opt/payara41/glassfish/domains/domain1/config/

I added the line org.springframework=WARNING at the end of the last file given above, and restarted my server. That didn't seem to have an effect. When I open the asadmin shell /opt/payara41/bin/asadmin and run list-log-attributes, here is what I get:

asadmin> list-log-attributes
com.sun.enterprise.server.logging.GFFileHandler.excludeFields   <>
com.sun.enterprise.server.logging.GFFileHandler.file    <${com.sun.aas.instanceRoot}/logs/server.log>
com.sun.enterprise.server.logging.GFFileHandler.flushFrequency  <1>
com.sun.enterprise.server.logging.GFFileHandler.formatter   <com.sun.enterprise.server.logging.ODLLogFormatter>
com.sun.enterprise.server.logging.GFFileHandler.logtoConsole    <false>
com.sun.enterprise.server.logging.GFFileHandler.maxHistoryFiles <0>
com.sun.enterprise.server.logging.GFFileHandler.multiLineMode   <true>
com.sun.enterprise.server.logging.GFFileHandler.retainErrorsStasticsForHours    <0>
com.sun.enterprise.server.logging.GFFileHandler.rotationLimitInBytes    <2000000>
com.sun.enterprise.server.logging.GFFileHandler.rotationOnDateChange    <false>
com.sun.enterprise.server.logging.GFFileHandler.rotationTimelimitInMinutes  <0>
com.sun.enterprise.server.logging.SyslogHandler.useSystemLogging    <false>
handlerServices <com.sun.enterprise.server.logging.GFFileHandler,com.sun.enterprise.server.logging.SyslogHandler>
handlers    <java.util.logging.ConsoleHandler>
java.util.logging.ConsoleHandler.formatter  <com.sun.enterprise.server.logging.UniformLogFormatter>
java.util.logging.FileHandler.count <1>
java.util.logging.FileHandler.formatter <java.util.logging.XMLFormatter>
java.util.logging.FileHandler.limit <50000>
java.util.logging.FileHandler.pattern   <%h/java%u.log>   <warn>
org.springframework <WARNING>
Command list-log-attributes executed successfully.

I have tried the suggestions given in this SO question but that didn't work. I'm stumped. :( I really do not want to see all those INFO logging lines printed by the spring framework.

=== EDIT ===

Here is what is in my (copied from SO):

# Define the root logger with appender file
log4j.rootLogger = DEBUG, stdout

# Define the file appender
# Set the name of the logs destination

# Set the immediate flush to true (default)

# Set the threshold to debug mode

# Set the append to false, overwrite

# Define the layout for appender

Here are all the places I have copied that file to:


In addition, I have added and org.springframework=WARNING to Configurations > server-config > Logger Settings > Module Log Levels in the Payara UI. Nothing is working. Payara's server log still has INFO lines for the spring framework.


I tried everything that has been suggested so far, to no avail. So I ended up doing something pretty hacky. I wrote my own log handler and installed it to domain1/lib/ext:

package org.springsuppressor;

import java.util.logging.ConsoleHandler;
import java.util.logging.Level;

public class MyHandler extends ConsoleHandler {

  public MyHandler() {

The handler above sets the log level for all loggers to WARNING. I could suppress messages for just the spring framework, but I don't yet need to do that.


I have a web app that uses log4j. I have configured a custom logger in the /WEB-INF/classes/ file like the following :

log4j.rootLogger=ERROR, CNSL

log4j.appender.CNSL.layout.ConversionPattern=%d{HH:mm:ss:SSS} %p %c (%F:%L) - %m%n = INFO

The log messages are written to the server.log as expected but am trying to find a way to control the custom logger log levels via the glassfish server.

I tried creating the logger in glassfish from the command :

asadmin set-log-level 

however all INFO messages are still logged even though the logger is set to WARNING by the asadmin command. Is there a way to control the logger level of the custom loggers configured in the from the glassfish loggers?


You can control the log level through the console in Glassfish if you use java.util.logging as underlying logging framework in your web application.

You can also use SLF4J in your code and use java.util.logging as underlying logging framework (through slf4j-jdk14.jar).