From: Ashish A. <aaw...@us...> - 2004-06-14 12:01:50
|
Update of /cvsroot/smartfrog/core/components/ssh/src/org/smartfrog/services/ssh In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6692 Modified Files: SSHExecImpl.java Log Message: Added Logging Support. Index: SSHExecImpl.java =================================================================== RCS file: /cvsroot/smartfrog/core/components/ssh/src/org/smartfrog/services/ssh/SSHExecImpl.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** SSHExecImpl.java 14 Jun 2004 09:55:13 -0000 1.1 --- SSHExecImpl.java 14 Jun 2004 12:01:42 -0000 1.2 *************** *** 42,45 **** --- 42,46 ---- import org.smartfrog.sfcore.prim.TerminationRecord; import org.smartfrog.sfcore.reference.Reference; + import org.smartfrog.sfcore.logging.Log; /** *************** *** 60,64 **** private String userName; private String password; - private String keyfile; private int port = SSH_PORT; private boolean failOnError = true; --- 61,64 ---- *************** *** 71,74 **** --- 71,75 ---- private Thread waitThread = null; private Session session = null; + private Log log; /** * Constructs SSHExecImpl object. *************** *** 91,97 **** --- 92,101 ---- RemoteException { super.sfDeploy(); + log = sfGetApplicationLog(); + assert log != null; readSFAttributes(); userInfo = new UserInfoImpl(trustAllCerts); userInfo.setName(userName); + log.info("User Name: "+ userName); userInfo.setPassword(password); } *************** *** 109,112 **** --- 113,117 ---- try { // open ssh session + logDebugMsg("Getting SSH Session"); session = openSession(); session.setTimeout((int) timeout); *************** *** 117,120 **** --- 122,126 ---- openChannel("exec"); String cmd = (String) commandsList.get(i); + log.info("Executing command:"+ cmd); channel.setCommand(cmd); channel.connect(); *************** *** 130,134 **** sleep(500); } catch (Exception e) { ! // ignored } } --- 136,140 ---- sleep(500); } catch (Exception e) { ! ignore(e); } } *************** *** 145,150 **** throw new SmartFrogException(TIMEOUT_MESSAGE); } else { ! // TODO: use logger ! System.out.println(TIMEOUT_MESSAGE); } } else { --- 151,155 ---- throw new SmartFrogException(TIMEOUT_MESSAGE); } else { ! log.error(TIMEOUT_MESSAGE); } } else { *************** *** 162,165 **** --- 167,171 ---- // check if it should terminate by itself if(shouldTerminate) { + log.info("Normal termination :" + sfCompleteNameSafe()); TerminationRecord termR = new TerminationRecord("normal", "SSH Session finished: ",sfCompleteName()); *************** *** 174,178 **** throw new SmartFrogLifecycleException(TIMEOUT_MESSAGE, e); } else { ! System.out.println(TIMEOUT_MESSAGE); } } else { --- 180,184 ---- throw new SmartFrogLifecycleException(TIMEOUT_MESSAGE, e); } else { ! log.error(TIMEOUT_MESSAGE); } } else { *************** *** 182,186 **** } }catch (Exception e) { ! e.printStackTrace(); throw new SmartFrogLifecycleException(e); } --- 188,194 ---- } }catch (Exception e) { ! if(log.isTraceEnabled()) { ! log.trace(e); ! } throw new SmartFrogLifecycleException(e); } *************** *** 234,238 **** session.setUserInfo(userInfo); session.setPassword(password); ! System.out.println("Connecting to " + host + ":" + port); session.connect(); return session; --- 242,246 ---- session.setUserInfo(userInfo); session.setPassword(password); ! log.info("Connecting to " + host + " at Port:" + port); session.connect(); return session; *************** *** 241,244 **** --- 249,270 ---- return failOnError; } + /** + * Logs debug message + * @param msg debug message + */ + private void logDebugMsg(String msg) { + if (log.isDebugEnabled()) { + log.debug(msg); + } + } + /** + * Logs ignored exception + * @param msg debug message + */ + private void ignore(Exception e) { + if (log.isDebugEnabled()) { + log.debug("Ignoring Exception:" + e); + } + } } |