📄 logviewer.java
字号:
/*
* Copyright (C) 2006-2007 Funambol
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package com.funambol.util;
import javax.microedition.rms.RecordEnumeration;
import javax.microedition.rms.RecordStore;
import javax.microedition.rms.RecordStoreException;
import javax.microedition.rms.RecordStoreNotOpenException;
/**
* A class useful to see the content of Log RecordStore generated by RMSAppender
*
*/
public class LogViewer {
//---------------------------------------------------------------- Constants
/**
* Pass this value to <code>getLogEntries(int mode)</code> method
* for RMS Log Mode
*/
public static final int RMSLOG = 0;
/**
* Pass this value to <code>getLogEntries(int mode)</code> method
* for File Log Mode
*/
public static final int JSR75LOG = 1;
//------------------------------------------------------------- Constructors
/**
* Creates a new instance of LogViewer
*/
public LogViewer() {
}
//----------------------------------------------------------- Public Methods
/**
* This method return a String array that contain the log file content
* in form of String objects. For now it just can access RMS Log file,
* but empty method for accessing JSR75 Log file is provided.
*
* @return a String array that contain the specified log
*/
public String[] getLogEntries(int mode) {
String[] logArray = null;
if (mode == RMSLOG) {
logArray = getRMSLogStrings();
} else if (mode == JSR75LOG) {
Log.info("JSR75 will be supported in future versions");
}
return logArray;
}
//-----------------------------------------------------------Private Methods
/**
* Recursively scan the Log RecordStore RMSAppender.LOGDBNAME
* and store its content into a String array of String objects.
*
* @return result String array that contains all log messages
*/
private String[] getRMSLogStrings() {
RecordStore rs = null;
String[] result = null;
try {
rs = RecordStore.openRecordStore(RMSAppender.LOGDBNAME, true);
int size = rs.getNumRecords();
if (size == 0) {
result = new String[1];
result[0] = "No Log entries found.";
} else {
result = recordsToStringArray(rs);
}
rs.closeRecordStore();
} catch (RecordStoreException ex) {
Log.error(this, "getRMSLogStrings() recordstore Exception");
ex.printStackTrace();
}
return result;
}
private String[] recordsToStringArray(RecordStore rs) throws RecordStoreNotOpenException {
int i=0;
String[] result = new String[rs.getNumRecords()];
RecordEnumeration re = rs.enumerateRecords(null, null, false);
while (re.hasNextElement()) {
try {
result [i++] = new String(re.nextRecord());
} catch (Throwable t) {
Log.error("throwable catched at recordsStoStringArray: "+ t.toString());
t.printStackTrace();
}
}
return result;
}
/**
* JSR75 Log File viewer. It will be implemented in future versions.
*/
private void getJsr75LogFile() {
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -