aspose file tools*
The moose likes Java in General and the fly likes custom java logging format issues using java.util.logging Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "custom java logging format issues using java.util.logging" Watch "custom java logging format issues using java.util.logging" New topic
Author

custom java logging format issues using java.util.logging

s ravi chandran
Ranch Hand

Joined: Dec 20, 2010
Posts: 154
hi

I am adding logging facility in my project and i have created a logging class which i am calling everywhere in the project classes and defining level of logging based on requirement. now the issue which i am facing is the way i want the logging to happen. I have written a logger formatting class, the code is given below :



this class is working, but it is not the desired result.

the current logging format is :



whereas my intended format for normal logging is :



As I am using a single class in the project, i am unable to call getSourceClassName() and getSourceMethodName() method on LogRecord object. I dont know if there is any other way for that or not.

the other part of the problem is showing the log in case of error or exception, i have created a method in which i convert the stacktrace to string and pass it to logger class, but again the format is not like what i would like to see. this are the statements i am using :



here again the intended format is :



please guide in this.

thanks
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19720
    
  20

s ravi chandran wrote:As I am using a single class in the project, i am unable to call getSourceClassName() and getSourceMethodName() method on LogRecord object.

I don't get why you're unable to use the two methods that are created for what you want. If you're using only a single class, then your logs should show only this single class, as there won't be any other source of the exceptions (except maybe API methods called with invalid arguments).
s ravi chandran
Ranch Hand

Joined: Dec 20, 2010
Posts: 154
Rob Spoor wrote:
s ravi chandran wrote:As I am using a single class in the project, i am unable to call getSourceClassName() and getSourceMethodName() method on LogRecord object.

I don't get why you're unable to use the two methods that are created for what you want. If you're using only a single class, then your logs should show only this single class, as there won't be any other source of the exceptions (except maybe API methods called with invalid arguments).


well, i am using a class MyLogger, this class is called in all the project classes wherever i am logging something. now if i call getSourceClassName() method, i get the name as MyLogger, and the method name is also from MyLogger class. I am not creating individual logger object in each class, maybe in that way these methods will be useful.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: custom java logging format issues using java.util.logging