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 3213556
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T14:57:30+00:00 2026-05-17T14:57:30+00:00

I have a webapplication and I want to use a different log for every

  • 0

I have a webapplication and I want to use a different log for every user, so I can have a “history” of what the user did on the system.

This is what I have so far:

import java.io.File;
import java.io.IOException;

import org.apache.log4j.DailyRollingFileAppender;
import org.apache.log4j.FileAppender;
import org.apache.log4j.SimpleLayout;
import org.apache.log4j.Logger;

public class LogManager {

    public Logger getLog(String username) throws IOException{
        SimpleLayout layout = new SimpleLayout(); 
        FileAppender appender = new DailyRollingFileAppender(layout, "users"+File.pathSeparator+username+File.pathSeparator+username, "'.'yyyy-MM");

        // configure the appender here, with file location, etc
        appender.activateOptions();
        Logger logger = Logger.getRootLogger();
        logger.addAppender(appender);
        return logger;
    }

}

The problem is that, as a webapplication, is multithreaded, so AFAIK I can’t use RootLogger all the time and change the appenders depending on the user who I’m logging. I think I should create different Logger for each user, but is that correct?

  • 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-17T14:57:30+00:00Added an answer on May 17, 2026 at 2:57 pm

    Try switching to logback (log4j’s successor). It comes with a SiftingAppender which can be used to separate (or sift) logging according to a given runtime attribute, which would be “userid” in your case. The documentation contains an example for separating logs based on userid.

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

Sidebar

Related Questions

I have user information which I need to use in different places on the
I have a .Net 2.0/3.5 WebApplication. I want to be able to take money
I have this web application that has grown to an unmanageable mess. I want
I have two webapplication, one is a simple authenticationsite which can authenticate the logged
I have a webapplication where I use a registry class. The registry class holds
Currently I'm working on a on-line webapplication for construction materials. Companies can log in
I have a web application using ASP.NET 2.0 and I want to know if
I have a web application that is becoming rather large. I want to separate
I have a web server that runs my web application. If I want to
I have a WebApplication project, a business logic project, and a WebDeployment project for

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.