Question

I'm having trouble configuring logging correctly for a deployed application using Maven and Embedded Glassfish 4. The server will show log messages that I have set to INFO but not DEBUG. The logging config I have works fine when deployed to standalone Glassfish 4 but I'm unable to work out why it doesn't on the embedded version.

I have the following dependencies for my app in the pom.xml:

        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <version>1.0.13</version>
        </dependency>                
        <dependency>
            <groupId>org.codehaus.groovy</groupId>
            <artifactId>groovy-all</artifactId>
            <version>2.0.7</version>
        </dependency>

And the embedded glassfish plugin is configured as follows in the pom.xml:

           <plugin>
            <groupId>org.glassfish.embedded</groupId>
            <artifactId>maven-embedded-glassfish-plugin</artifactId>
            <version>4.0</version>
            <configuration>
                <goalPrefix>embedded-glassfish</goalPrefix>
                <name>ia</name>
                <app>target/${project.artifactId}-${project.version}</app>
                <autoDelete>true</autoDelete>
                <configFile>glassfish/domain.xml</configFile>
            </configuration>
            <executions>
                <!-- Start embedded GlassFish -->
                <execution>
                    <id>start</id>
                    <phase>pre-integration-test</phase>
                    <goals>
                        <goal>start</goal>
                    </goals>
                </execution>
                <execution>
                    <id>deploy</id>
                    <phase>pre-integration-test</phase>
                    <goals>
                        <goal>deploy</goal>
                    </goals>
                </execution>
                <execution>
                    <id>stop</id>
                    <phase>post-integration-test</phase>
                    <goals>
                        <goal>undeploy</goal>
                        <goal>stop</goal>
                    </goals>
                </execution>
                <!-- Run some admin commands -->
                <execution>
                    <id>admin</id>
                    <phase>install</phase>
                    <goals>
                        <goal>admin</goal>
                    </goals>
                    <configuration>
                        <commands>
                            <param>list-applications</param>
                        </commands>
                    </configuration>
                </execution>
            </executions>
            <dependencies>
                <dependency>
                    <groupId>org.glassfish.main.extras</groupId>
                    <artifactId>glassfish-embedded-all</artifactId>
                    <version>4.0</version>
                </dependency>
                <dependency>
                    <groupId>com.oracle</groupId>
                    <artifactId>ojdbc6</artifactId>
                    <version>${ojdbc6.version}</version>
                    <type>jar</type>
                </dependency>
            </dependencies>
        </plugin>

Note - I have used the domain.xml created using a standalone instance of Glassfish to provide me with various pre-configured resources.

And my logback.groovy config file looks like:

def appenderList = ["ROLLING"]
def WEBAPP_DIR = "."
def APPENDER_PATTERN = "%d{yyyy-MM-dd HH:mm:ss.SSS}:%5p:%c{1}:%M:%L: %m%n";
def consoleAppender = true;

println "Hostname is ${hostname}"
// does hostname match PROD?
if (hostname =~ /PROD/) { // TODO: replace this with actual produtcion server host URL pattern
  WEBAPP_DIR = "/opt/myapp" // TODO: replace with actual web app directory
  consoleAppender = false
} else {
  appenderList.add("CONSOLE")
  logger("uk.co.myapp", DEBUG, ["CONSOLE"])
}

if (consoleAppender) {
    appender("CONSOLE", ConsoleAppender) {
      encoder(PatternLayoutEncoder) {
        pattern = "${APPENDER_PATTERN}"
      }
    }
}

appender("ROLLING", RollingFileAppender) {
  file = "${WEBAPP_DIR}/log/ia-log.log"
  encoder(PatternLayoutEncoder) {
    pattern = "${APPENDER_PATTERN}"
  }
  rollingPolicy(TimeBasedRollingPolicy) {
    fileNamePattern = "${WEBAPP_DIR}/log/ia-log-%d{yyyy-MM}.zip"
  }
}

root(INFO, appenderList)

I've worked out how to change the logging.properties for the Glassfish server, but so far my changes to these settings have no effect on my deployed application, they just spew out loads of server related log messages which I don't care about.

I'm hoping someone has experienced this same problem and worked out how to configure it properly.

Preferably I want to stick with logback but if it means switching logging frameworks to solve this problem then I'll be happy to do so.

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top