cancel
Showing results for 
Search instead for 
Did you mean: 

how to print stacktrace in log using logging

Former Member
0 Kudos

Hi All ,

I am using logging in my webdynpro application

I hv written following java class for logging

***************************************java class Starts *******************************

public class ReferenceApplicationEJBLogger {

private static final Location LOCATION = Location.getLocation("com.apl");

private static final Category CATEGORY = Category.getCategory(Category.APPLICATIONS, "Reference Application");

static{

LOCATION.setMinimumSeverity(CATEGORY, Severity.INFO);

LOCATION.setMaximumSeverity(CATEGORY, Severity.ALL);

CATEGORY.addLog(new FileLog("./log/application/hrhelpdesk/edmProject.%g.trc"));

}

public static void logException (Exception eMessage){

logThrowable(eMessage);

eMessage.printStackTrace();

}

public static void logThrowable (Throwable eMessage){

CATEGORY.logThrowableT(Severity.WARNING, LOCATION, eMessage.getLocalizedMessage(), eMessage);

}

public static void logWarning (String logWarning, Exception eMessage) {

CATEGORY.warningT(LOCATION, logWarning, new Object[]{eMessage});

}

public static void logInfo (String logString){

CATEGORY.infoT(LOCATION, logString);

}

public static void logWarn (String logString){

CATEGORY.warningT(LOCATION, logString);

}

}

***********************************Java class ends here **********************************

and inside my webdynpro applicaiton i have written following code in side catch block

ReferenceApplicationEJBLogger.logInfo("Error occured in application" );

log is getting written in to defined locaiton ./log/application/hrhelpdesk/edmProject.%g.trc

but i also want to print e.printStackTrce() in above mentioned location along with message "Error occured in application".

How to go about it ? Thnx in advance

Regards

Kavita

Accepted Solutions (0)

Answers (1)

Answers (1)

nitin_mahajan2
Contributor
0 Kudos

Let me understand first, are you looking at printing the complete exception log?

catch (Exception e) {

StringWriter sw = new StringWriter();

PrintWriter pw = new PrintWriter(sw);

e.printStackTrace(pw);

System.out.println(sw.toString().toUpperCase());

}

Tested, it works.

Regards,

Nitin

Edited by: Nitin Mahajan on May 28, 2009 9:51 PM

Former Member
0 Kudos

ya it worked for me also. but still it is writing data to location created for my application and also in ./log folder in trc file. I don't want to put it to ./log in trc file. I want to write only in location created for my application

Regards

Kavita

nitin_mahajan2
Contributor
0 Kudos

The standard log files content is controlled by server. For that you will have to setup in Visual admin log service. I dont remember the name of the service, but there you can set the logging level to info/error etc...

Regards,

Nitin

Former Member
0 Kudos

thnx. i will try n let u know.

Regards

Kavita