本站不再更新,欢迎光临 java开发技术网
随笔-230  评论-230  文章-8  trackbacks-0

package com.ff.utils;

import java.util.Date;

import net.rim.device.api.system.EventLogger;

/**
 * 日志类
 * @author   2010-09-04
 *
 */
public class Logger {

 private static final String SEPARATOR = "   ";
 private static final long GUID = 0x4c9d3452d880a2f1L;
 private static final String APP_NAME = "xxxc ";

 private Logger() {
  EventLogger.register(GUID, APP_NAME, EventLogger.VIEWER_STRING);
 }

 private static Logger logger = new Logger();

 public static Logger getLogger() {
  return logger;
 }

 /**
  * Log the information.
  *
  * @param message
  *            The message you will log
  */
 public void info(String message) {
  if (message == null || message.trim().equals(""))
   return;
  String log = "INFO: " + new Date().toString() + SEPARATOR + message;
  try {
   log = new String(log.getBytes(), "UTF-8");
   byte[] msg_bytes = log.getBytes();
   EventLogger.logEvent(GUID, msg_bytes, EventLogger.ALWAYS_LOG);
  } catch (Exception ex) {
   System.err.println(ex);
  }
 }

 public void error(Exception e) {
  StringBuffer log = new StringBuffer();
  log.append("ERROR: " + new Date().toString() + SEPARATOR);
  log.append(e.getMessage() + " \r\n ");

  try {
   byte[] msg_bytes = new String(log.toString().getBytes(), "UTF-8").getBytes();
   EventLogger.logEvent(GUID, msg_bytes);
  } catch (Exception ex) {
   System.err.println(ex);
  }
 }
 
 public void error(String message, Exception e) {
  StringBuffer log = new StringBuffer();
  log.append("ERROR: " + new Date().toString() + SEPARATOR);
  if (message != null || !message.trim().equals("")) {
   log.append("message: " + message + " \r\n ");
  }
  log.append("error: " + e.getMessage() + " \r\n ");

  try {
   byte[] msg_bytes = new String(log.toString().getBytes(), "UTF-8").getBytes();
   EventLogger.logEvent(GUID, msg_bytes);
  } catch (Exception ex) {
   System.err.println(ex);
  }
 }
}


不管是在模拟器还是真机,日志还是必须的......如果该文对你有用,为了表示对作者的支持,麻烦你单击一下下面的广告,谢谢

posted on 2010-09-05 16:55 有猫相伴的日子 阅读(562) 评论(0)  编辑  收藏 所属分类: blackberry

只有注册用户登录后才能发表评论。


网站导航:
 
本站不再更新,欢迎光临 java开发技术网