This week's book giveaway is in the NodeJS forum.
We're giving away four copies of Serverless Applications with Node.js and have Slobodan Stojanovic & Aleksandar Simovic on-line!
See this thread for details.
Win a copy of Serverless Applications with Node.js this week in the NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Ron McLeod
  • Tim Moores
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Vijitha Kumara

Log4j From Thread is not writing to Log File but writing to Console  RSS feed

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a web application with multi threading. Application flow is in such a way that certain classes uses multithreading and am using FutureTask for it. I have to generate a log in one of the classes which is invoked by each thread.

If I do Logger employeeLog = Logger.getLogger("Employee"); in classes which are not executed by a Thread the logs are written to the file.

If I use same initialization Logger employeeLog = Logger.getLogger("Employee"); in classes which are part of the thread, the logs are written to console but not appending to a file.

Below is my log4j.xml

 
Ranch Hand
Posts: 104
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you using a different classloader in your FutureTask callable, which loads files from different classpath? log4j, by default, takes its configuration from the log4j.xml in the classpath.
 
Hemanth KumarKumar
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Salil Wadnerkar wrote:Are you using a different classloader in your FutureTask callable, which loads files from different classpath? log4j, by default, takes its configuration from the log4j.xml in the classpath.



Hi Salil - No, am not loading log4j again in FutureTask callable.

In my init servlet of application I do this :


and in CustomLoggerWrapper
 
Salil Wadnerkar
Ranch Hand
Posts: 104
 
Time is the best teacher, but unfortunately, it kills all of its students - Robin Williams. tiny ad:
Create Edit Print & Convert PDF Using Free API with Java
https://coderanch.com/wiki/703735/Create-Convert-PDF-Free-Spire
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!