As we all know blackberry development is little hectic. We don’t have very strong IDE which will fulfill each of the developers needs. Eclipse has covered most of them. but however it doesn’t provide support for printing logs while it is in run mode. Each time to print logs we need to start the simulator in debug mode. Here is the solution for that. Using this we can write logs to the a file. Before that just do a setup for the Simulator SD card. enjoy this..
public static void writeLog(String data){ FileConnection fc = null; OutputStream lStream = null; Date d = new Date(); Calendar c = Calendar.getInstance(); String time = new String(); if (pFilePath != null) { try { fc = (FileConnection)Connector.open("file:///" + pFilePath,Connector.READ_WRITE); if(null == fc || fc.exists() == false){ fc.create(); } lStream = fc.openOutputStream(fc.fileSize()); c.setTime(d); time = c.get(Calendar.HOUR_OF_DAY) + ":" +c.get(Calendar.MINUTE) + ":" + c.get(Calendar.SECOND) + ":" + c.get(Calendar.MILLISECOND); data = "\n"+time + "("+ (System.currentTimeMillis() - currentTimeMillies) + " ms)" + " -- " + data; currentTimeMillies = System.currentTimeMillis(); lStream.write(data.getBytes()); } catch (Exception ioex) { ioex.printStackTrace(); } finally { if (lStream != null) { try { lStream.close(); lStream = null; } catch (Exception ioex){ } } if (fc != null) { try { fc.close(); fc = null; } catch (Exception ioex){ } } } } }
