[JIRA] Created: (LBCORE-171) Can't use logback on GAE SDK 1.3.7 when configured with logback.xml

Can't use logback on GAE SDK 1.3.7 when configured with logback.xml ------------------------------------------------------------------- Key: LBCORE-171 URL: http://jira.qos.ch/browse/LBCORE-171 Project: logback-core Issue Type: Bug Affects Versions: 0.9.24 Environment: GAE/J 1.3.7 Reporter: Maxim Veksler Assignee: Logback dev list Trying to initialize logback with custom configuration file (logback.xml) running on GAE platform throws the following exception Failed to instantiate [ch.qos.logback.classic.LoggerContext] Reported exception: java.lang.NoClassDefFoundError: java.net.InetAddress is a restricted class. Please see the Google App Engine developer's guide for more details. at com.google.appengine.tools.development.agent.runtime.Runtime.reject(Runtime.java:51) at ch.qos.logback.core.util.ContextUtil.getLocalHostName(ContextUtil.java:30) at ch.qos.logback.core.util.ContextUtil.addHostNameAsProperty(ContextUtil.java:39) at ch.qos.logback.classic.joran.action.ConfigurationAction.begin(ConfigurationAction.java:47) at ch.qos.logback.core.joran.spi.Interpreter.callBeginAction(Interpreter.java:273) at ch.qos.logback.core.joran.spi.Interpreter.startElement(Interpreter.java:145) at ch.qos.logback.core.joran.spi.Interpreter.startElement(Interpreter.java:127) at ch.qos.logback.core.joran.spi.EventPlayer.play(EventPlayer.java:40) at ch.qos.logback.core.joran.spi.Interpreter.play(Interpreter.java:332) at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:126) at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:93) at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:52) at ch.qos.logback.classic.util.ContextInitializer.configureByResource(ContextInitializer.java:77) at ch.qos.logback.classic.util.ContextInitializer.autoConfig(ContextInitializer.java:150) at org.slf4j.impl.StaticLoggerBinder.init(StaticLoggerBinder.java:85) at org.slf4j.impl.StaticLoggerBinder.<clinit>(StaticLoggerBinder.java:55) at org.slf4j.LoggerFactory.bind(LoggerFactory.java:121) at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:111) at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:268) at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:241) at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:254) ...... This happens because ch.qos.logback.core.util.ContextUtil.java contains are reference to a java.net.InetAddress which is a restricted class on Google AppEngine Platform SDK 1.3.7: static String getLocalHostName() throws UnknownHostException { InetAddress localhost = InetAddress.getLocalHost(); return localhost.getHostName(); } I should note that BasicConfigurator is working and is able to configure the logback subsystem. A couple of resolutions I can think of: 1. Don't export this parameter by default, instead let the user choose if to define it or not in the logback.xml configuration file. 2. Create a "GAEConfigurator" which will use default for the limited GAE environment. 2. Provide a custom build for GAE platform, where this parameter will be taken from http://code.google.com/appengine/docs/java/javadoc/com/google/appengine/api/... or not be defined at all. 4. Provide some method to override / use a different implementation of ContextUtil, one which will be suitable for GAE. -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://jira.qos.ch/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira

[ http://jira.qos.ch/browse/LBCORE-171?page=com.atlassian.jira.plugin.system.i... ] Maxim Veksler commented on LBCORE-171: -------------------------------------- Work around, based on the following thread http://www.mail-archive.com/google-appengine-java@googlegroups.com/msg12031.... Create in your project the following class (taken from version 0.9.24 of logback): === /** * Logback: the reliable, generic, fast and flexible logging framework. * Copyright (C) 1999-2010, QOS.ch. All rights reserved. * * This program and the accompanying materials are dual-licensed under either * the terms of the Eclipse Public License v1.0 as published by the Eclipse * Foundation * * or (per the licensee's choosing) * * under the terms of the GNU Lesser General Public License version 2.1 as * published by the Free Software Foundation. */ package ch.qos.logback.core.util; import java.net.InetAddress; import java.net.UnknownHostException; import com.google.appengine.api.utils.SystemProperty; import ch.qos.logback.core.Context; import ch.qos.logback.core.CoreConstants; import ch.qos.logback.core.spi.ContextAwareBase; public class ContextUtil extends ContextAwareBase { public ContextUtil(Context context) { setContext(context); } static String getLocalHostName() throws UnknownHostException { return SystemProperty.applicationId.get(); } /** * Add the local host's name as a property */ public void addHostNameAsProperty() { try { String localhostName = getLocalHostName(); context.putProperty(CoreConstants.HOSTNAME_KEY, localhostName); } catch (UnknownHostException e) { addError("Failed to get local hostname", e); } catch (SecurityException e) { addError("Failed to get local hostname", e); } } } ===
Can't use logback on GAE SDK 1.3.7 when configured with logback.xml -------------------------------------------------------------------
Key: LBCORE-171 URL: http://jira.qos.ch/browse/LBCORE-171 Project: logback-core Issue Type: Bug Affects Versions: 0.9.24 Environment: GAE/J 1.3.7 Reporter: Maxim Veksler Assignee: Logback dev list
Trying to initialize logback with custom configuration file (logback.xml) running on GAE platform throws the following exception Failed to instantiate [ch.qos.logback.classic.LoggerContext] Reported exception: java.lang.NoClassDefFoundError: java.net.InetAddress is a restricted class. Please see the Google App Engine developer's guide for more details. at com.google.appengine.tools.development.agent.runtime.Runtime.reject(Runtime.java:51) at ch.qos.logback.core.util.ContextUtil.getLocalHostName(ContextUtil.java:30) at ch.qos.logback.core.util.ContextUtil.addHostNameAsProperty(ContextUtil.java:39) at ch.qos.logback.classic.joran.action.ConfigurationAction.begin(ConfigurationAction.java:47) at ch.qos.logback.core.joran.spi.Interpreter.callBeginAction(Interpreter.java:273) at ch.qos.logback.core.joran.spi.Interpreter.startElement(Interpreter.java:145) at ch.qos.logback.core.joran.spi.Interpreter.startElement(Interpreter.java:127) at ch.qos.logback.core.joran.spi.EventPlayer.play(EventPlayer.java:40) at ch.qos.logback.core.joran.spi.Interpreter.play(Interpreter.java:332) at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:126) at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:93) at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:52) at ch.qos.logback.classic.util.ContextInitializer.configureByResource(ContextInitializer.java:77) at ch.qos.logback.classic.util.ContextInitializer.autoConfig(ContextInitializer.java:150) at org.slf4j.impl.StaticLoggerBinder.init(StaticLoggerBinder.java:85) at org.slf4j.impl.StaticLoggerBinder.<clinit>(StaticLoggerBinder.java:55) at org.slf4j.LoggerFactory.bind(LoggerFactory.java:121) at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:111) at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:268) at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:241) at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:254) ...... This happens because ch.qos.logback.core.util.ContextUtil.java contains are reference to a java.net.InetAddress which is a restricted class on Google AppEngine Platform SDK 1.3.7: static String getLocalHostName() throws UnknownHostException { InetAddress localhost = InetAddress.getLocalHost(); return localhost.getHostName(); } I should note that BasicConfigurator is working and is able to configure the logback subsystem. A couple of resolutions I can think of: 1. Don't export this parameter by default, instead let the user choose if to define it or not in the logback.xml configuration file. 2. Create a "GAEConfigurator" which will use default for the limited GAE environment. 2. Provide a custom build for GAE platform, where this parameter will be taken from http://code.google.com/appengine/docs/java/javadoc/com/google/appengine/api/... or not be defined at all. 4. Provide some method to override / use a different implementation of ContextUtil, one which will be suitable for GAE.
-- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://jira.qos.ch/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira

participants (2)
-
Maxim Veksler (JIRA)
-
ori (JIRA)