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

  • SEARCH
  • Home
  • 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 3998206
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T07:29:49+00:00 2026-05-20T07:29:49+00:00

I have an application with multiple controllers, and I’d like to have each log

  • 0

I have an application with multiple “controllers”, and I’d like to have each log to their own file. This is easy enough for their own code, but I’m also using some library code which uses commons logging. Could I somehow get that code to log to the controller-specific file as well?

I was thinking I could somehow do it by thread:

class Controller {

 public void action() {
  setCurrentThreadLogFile(myLogFile);
  try {
   Library.stuff();
  } finally {
   restoreCurrentThreadLogFile();
  }
 }

}

Currently I’m using commons-logging for my own logging as well, with log4j as backend. But I could change that, if needed, or use a mix (is that’s possible within the commons logging framework).

One way I could do this would be to write my own commons logging implementation (possibly a wrapper around log4j), but is there an existing solution?

  • 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-20T07:29:50+00:00Added an answer on May 20, 2026 at 7:29 am

    You probably want to be looking at mapped diagnostic contexts (MDCs). Commons logging does not support these but Log4J does, so you would have to go directly to Log4J to set this up. You will probably have to roll your own filter to filter using the MDC and apply to the appenders.

    If you willing to change logging implementations then you could use SL4J as the logging facade and Logback as the logging implementation. Have the controller or some sort of filter/interceptor add a discriminator value for a key you are going to use to discriminate the controllers with to the MDC. Use a SiftingAppender to separate the log event into separate files.

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

Sidebar

Related Questions

I have this error, Fatal error: Call to undefined method CI_Input::file() in D:\xampp\htdocs\application\controllers\page.php on
I have an application with multiple forms, each form has the same icon, so
there is a situation where a have multiple controllers like a town_center controller, a
I have my action available. Multiple people work on this application and there is
I have an iphone application with multiple views and related controllers and xib files.
I have two applications using ASP.NET MVC, each with multiple controllers. I want to
I have an iPhone application that contains several views and their associated controllers. Looking
I have this simple MVC 3 application which simply has two controllers(Home and Edit),
I have an iPhone Application with multiple view controllers , in all view controller's
I have multiple view controllers in my application with uipickerview (which get visible on

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.