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);
}
}
}
不管是在模擬器還是真機,日志還是必須的......如果該文對你有用,為了表示對作者的支持,麻煩你單擊一下下面的廣告,謝謝