use of com.tencent.wstt.gt.ui.model.LogEntry in project GT by Tencent.
the class SaveLogHelper method openLog.
public static LogEntry[] openLog(String filename, int maxLines) {
File catlogDir = getCatlogDirectory();
File logFile = new File(catlogDir, filename);
List<LogEntry> logLines = new ArrayList<LogEntry>();
BufferedReader bufferedReader = null;
try {
bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(logFile)), BUFFER);
while (bufferedReader.ready()) {
String line = bufferedReader.readLine();
if (null != line) {
LogEntry entry = new LogEntry();
entry.msg = line;
logLines.add(entry);
if (logLines.size() > maxLines) {
}
}
}
} catch (IOException ex) {
ex.printStackTrace();
} finally {
if (bufferedReader != null) {
try {
bufferedReader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return logLines.toArray(new LogEntry[] {});
}
use of com.tencent.wstt.gt.ui.model.LogEntry in project GT by Tencent.
the class GTLogInternal method log.
public static void log(long pid, int level, String tag, String msg, String sTime) {
if (level < Log_Level) {
return;
}
if (!log_enable_flag) {
return;
}
if (level > LOG_ERROR || null == tag || null == msg) {
return;
}
// 第一次打日志,初始化日志消费者对象。TODO 按道理说应该加锁。
if (null == logTaskConsumer) {
logTaskConsumer = new LogTaskConsumer(logController);
logTaskConsumer.setAllowAdd2Visable(log_enable_flag);
logTaskConsumer.start();
}
char sLevel = 'V';
switch(level) {
case LOG_VERBOSE:
sLevel = 'V';
break;
case LOG_DEBUG:
sLevel = 'D';
break;
case LOG_INFO:
sLevel = 'I';
break;
case LOG_WARNING:
sLevel = 'W';
break;
case LOG_ERROR:
sLevel = 'E';
break;
}
String time = sTime;
if (sTime == null) {
time = GTUtils.getSystemDateTime();
}
LogEntry entry = new LogEntry();
entry.tid = pid;
entry.tag = tag;
entry.level = level;
if (isSaveDefaultSeg()) {
StringBuffer sb = new StringBuffer();
sb.append(time);
sb.append(": ");
sb.append(sLevel);
// sb.append(" | ");
sb.append("/");
sb.append(tag);
// sb.append(" | ");
sb.append("(");
sb.append(pid);
// sb.append(" : ");
sb.append("): ");
sb.append(msg);
// sb.append("\r\n"); // 因为UI与自动保存分开了,所以不能统一加换行了
entry.msg = sb.toString();
} else {
entry.msg = msg;
}
entry.sTime = time;
logTaskConsumer.putLog(entry);
tempLogConsumer.putLog(entry.msg);
}
Aggregations