Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Centralised Logging in Application in Source Filename, Methodname , Line Number format.

 
Piyush Patel
Ranch Hand
Posts: 127
Android Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello friends,

in my Swing app, i created one LogWriter class.
to log statement from LoginForm.java file

i call LogWriter.init().
and then LogWriter.write("Login Succesfull or any message here");

output message is,
08/04/2010 11:11:19 AM com.piyush.util.LogWriter write
INFO: Login Successful or any message here

but i wanted it to be like, Source Filename, Methodname , Line Number format.
08/04/2010 11:11:19 AM com.piyush.LoginForm Login 39 (39 is line number in LogiForm.java)
INFO: Login Successful or any message here


see LogWriter.java

One more Question ,
Does logging run as Thread by default or developer needs to take care of this?
help ;)
 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I remember correctly the Log4J logging spawns its own thread(s) to log, as for the formatting, you should read the log4j documetnation and alter you log4j.xml appropriately.

Actually it looks like you're creating your own formatter, you'll need to read the Javadoc API for log4j to figure out what you need to set.
 
Piyush Patel
Ranch Hand
Posts: 127
Android Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,Martijn thanks for your reply.
can you tell me is my approach for centralized logging is right? need advice on this.

thanks ;)
 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's reasonable to have centralised services yes. Just make sure you're not duplicating effort of what Log4j already provides for you out of the box and make sure that the service is light weight!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic