Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6903971
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:59:30+00:00 2026-05-27T07:59:30+00:00

I’ve made an app init function that I’m using both in Java and GWT

  • 0

I’ve made an app init function that I’m using both in Java and GWT applications. I have external logback.xml file that I’m setting the path to the "logback.configurationFile" System property. In pure Java projects, all works as expected, but not in GWT projects.

I’ve implemented my ServletContextListener and in method contextInitialized I’m setting the System property. Logback does not read it, but falls back to basic (red letters in console).

So, I tried to follow instructions from logback configuration

LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();

to reconfigure Logback, but that throws

java.lang.ClassCastException: org.slf4j.impl.SimpleLoggerFactory cannot be cast to ch.qos.logback.classic.LoggerContext

I also tried to put logback.xml in folders: src, war, war/WEB_INF, but it doesn’t read it.

I’m switching to slf4j because previous log4j started to throw many "class not found" exceptions (something with commons-logging)

The question is:

  1. What is wrong?

    or

  2. How can I get sfl4j (logback) to read the external configuration XML file?

    or

  3. How can I get sfl4j (logback) to read any configuration XML file?

Help appreciated

EDIT: Tried to use log4j adapter with slf4j, and it doesn’t work either.

EDIT2: I reverted back to pure log4j that didn’t work before. However, I added log4j.jar directly in "Installed JRE" in Eclipse in the main system JRE and now the pure log4j works. What seems to me is that there is quite a difference between the OpenJDK and the Sun’s JDK, and that is causing problems. I’ll try to fix this slf4j issue in a few days. Maybe there is also a need for some jar on some weird place.

EDIT3: slf4j now works with log4j, but I have to manually configure it. Doesn’t matter where I put log4j.xml, it doesn’t read it. Looks like classloader problem with Sun’s JDK. I’ll try with Logback soon. It might be similar problem.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T07:59:31+00:00Added an answer on May 27, 2026 at 7:59 am

    There are a number of possible configurations with jetty, slf4j, and logback.
    It really depends on what you are trying to accomplish.

    1) Having the webapp itself do its own logging to logback.

    2) Having a global log at the server level that logs the server events and webapp events to logback.

    3) Having a global logback configuration at the server level that creates a log file for the server and individual log files for each webapp.

    To accomplish #1, you just have to put the slf4j and logback files in your webapp’s WEB-INF/lib directory and deploy the webapp. (be sure you put the configuration files in the webapps WEB-INF/classes or WEB-INF/ directory)

    To accomplish #2 and #3 you need to let jetty know that slf4j and logback should be exposed to all webapps, and that all webapps, regardless of the existence of their own (potential) slf4j and logback jars, they are to always use the jar files from the server.
    This is done by manipulating the WebAppContext’s list of systemClasses and serverClasses via the default web
    Slf4j is permitted through the webapp classloader barrier on Jetty, but logback is not.

    This can be defined statically in the context/*.xml deployable, or dynamically via a DeploymentManager binding. see the jetty-webapp-logging module on jetty.codehaus.org for details on how to accomplish this (I would link you do this, but codehaus is undergoing a server migration ATM)
    So, i gist’d the relevant file here – https://gist.github.com/1409147

    package org.mortbay.jetty.webapp.logging;
    
    import org.eclipse.jetty.deploy.App;
    import org.eclipse.jetty.deploy.AppLifeCycle;
    import org.eclipse.jetty.deploy.graph.Node;
    import org.eclipse.jetty.server.handler.ContextHandler;
    import org.eclipse.jetty.webapp.WebAppContext;
    
    public class CentralizedWebAppLoggingBinding implements AppLifeCycle.Binding
    {
        @Override
        public String[] getBindingTargets()
        {
            return new String[]
            { "deploying" };
        }
    
        @Override
        public void processBinding(Node node, App app) throws Exception
        {
            ContextHandler handler = app.getContextHandler();
            if (handler == null)
            {
                throw new NullPointerException("No Handler created for App: " + app);
            }
    
            if (handler instanceof WebAppContext)
            {
                WebAppContext webapp = (WebAppContext)handler;
                webapp.addSystemClass("org.apache.log4j.");
                webapp.addSystemClass("org.slf4j.");
                webapp.addSystemClass("org.apache.commons.logging.");
            }
        }
    }
    

    To accomplish #3 you’ll need to setup a slf4j MDC handler and sift logging in logback that uses the MDC information to route the appropriate logging event to the logfile of your choice.
    I blogged about this at http://webtide.intalio.com/2011/08/sifting-logs-in-jetty-with-logback/ and have example projects for basic logback, sifted logback, and even how to use the logback-access module for NCSA access logging at https://github.com/jetty-project/jetty-and-logback-example

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have thousands of HTML files to process using Groovy/Java and I need to
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I am writing an app with both english and french support. The app requests
I need a function that will clean a strings' special characters. I do NOT
I am using Paperclip to handle profile photo uploads in my app. They upload
link Im having trouble converting the html entites into html characters, (&# 8217;) i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.