blackberry 日志

blackberry 日志

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);
  }
 }
}


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

你可能感兴趣的:(blackberry 日志)