开发者

BlackBerry logging

I am implementing logging for a Bla开发者_开发知识库ckBerry app to track the flow of my application. What mechanisms do BlackBerry developers use to do this?


The EventLogger is a respectable API to start with. You can view the log on the device by holding 'alt' and hitting 'L' 'G' 'L' 'G'


One difficulty of the built in EventLogger is there's no programmatic way to read out of it. For that reason I implemented my own logger and included remote diagnostic capability.


I suggest you implement your own logging class as it provides lots of flexibility, e.g.

1) You can make the class send output to multiple locations so you can get quicker access to the logs when using a debugger, e.g.

/**
 * Internal function to encapsulate event logging
 *
 * @param msg   - message to log
 * @param level - log level to use, e.g. EventLogger.DEBUG_INFO, 
 *                INFORMATION, WARNING, ERROR, SEVERE_ERROR
 */
private void makeLog(String msg, int level)
{
  // You can also manipulate logs here, e.g.
  // -add the Class and/or Application name
  // -truncate or remove repeat logs, etc

  // Log to phone event log
  EventLogger.logEvent(ID, msg.getBytes(), level);

  // In the debugger log to the console
  System.err.println(msg);    
} 

2) For convenience you can add methods with readable names that log at the different severity levels, e.g.

public void debug(String msg)
{
  makeLog(msg, EventLogger.DEBUG_INFO);
}

Then you can call MyLogClass.debug("debug message") or MyLogClass.warning("warning message"), which makes it clearer on the importance of the log.


You can use the library https://sourceforge.net/projects/log4bb/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜