exception - log not printing the full stack trace -


i trying print whole stack trace in log file. here sample codes have written various classes. output of log file given. want whole stack trace printed in log.

first sample dao exception generated :

public string getpasswordbyemail(string email) throws userexception {     try {         beginnewtransaction();         preparedstatement stmt = getconnection().preparestatement(get_password_by_email);         stmt.setstring(1, email);          log.debug("preparestatement selecting user password email " + stmt.tostring());          resultset rs = stmt.executequery();         if(rs != null) {             rs.next();         }         return rs.getstring("password");     }     catch(sqlexception sqe) {         throw new userexception("could not retrieve user details",sqe);     } catch (jiffietransactionexception jte) {         throw new userexception("error while securing database connection", jte);     } } 

sample service class calls dao:

public string getpasswordbyemail(string email) throws userexception{     userdao userdao = new userdao();     return userdao.getpasswordbyemail(email); } 

sample action class catch , log exception :

 public string sendpasswordtoemail() {     userservice newservice = new userservice();     string password;     try {         password = newservice.getpasswordbyemail(email);     } catch (userexception e) {          log.error("error in retrievepasswordaction : "+e);         addactionerror("email id not registered");         return "failure";     }  /* more codes */ 

output of log file :

23 apr 2015 11:40:44,755 [http-bio-9999-exec-3] error retrievepasswordaction  - error in retrievepasswordaction : com.markeffy.aggregator.usernotfoundexception: email id not exist  

here my log4j.xml

<?xml version="1.0" encoding="utf-8"?> <configuration status="error"  dlog4jcontextselector="org.apache.logging.log4j.core.async.asyncloggercontext    selector"> <appenders> <file name="myfile"  filename="${sys:catalina.home}/logs/aggregator.log">   <patternlayout pattern= "%d{dd mmm yyyy hh:mm:ss,sss} [%t] %-5p %c{1} %x{user} - %m %n %throwable{full} %n"/>   </file>   </appenders>   <!-- <policies>     <sizebasedtriggeringpolicy size="5 kb"/>   </policies> -->  <!--  <defaultrolloverstrategy max="0"/>       </rollingrandomaccessfile> <async name="asyncrollingfile">   <appenderref ref="rollingfile"/> </async> -->  <console name="stdout" target="system_out">   <patternlayout pattern="%d %-5p [%t] %c{2} (%f:%l) - %m%n%n"/> </console>   <loggers>  <logger name="org.apache.log4j.xml" level="debug">   <appenderref ref="myfile"/> </logger> <root level="debug">   <appenderref ref="myfile"/> </root> </loggers> 

i want whole stack trace come in log file. appreciated.

the standard way log exception full stack trace

try {     ... } catch (someexception ex) {     logger.error("could not retrieve password", ex); // separate comma } 

your code snippet says log.error("error in retrievepasswordaction : "+e). problem using plus between error message , exception object. plus concatenates string on left object on right, resulting in new string. new string gets logged. equivalent to:

// concatenate string+e.tostring() new string string msg = "error in retrievepasswordaction : "+e;  log.error(msg); // log new string; not intended... 

Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -