Search in sources :

Example 6 with LogEntry

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[] {});
}
Also used : InputStreamReader(java.io.InputStreamReader) ArrayList(java.util.ArrayList) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) File(java.io.File) LogEntry(com.tencent.wstt.gt.ui.model.LogEntry) FileInputStream(java.io.FileInputStream)

Example 7 with 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);
}
Also used : LogEntry(com.tencent.wstt.gt.ui.model.LogEntry)

Aggregations

LogEntry (com.tencent.wstt.gt.ui.model.LogEntry)7 IOException (java.io.IOException)3 File (java.io.File)2 FileWriter (java.io.FileWriter)2 AsyncTask (android.os.AsyncTask)1 SearchLogAdapter (com.tencent.wstt.gt.log.SearchLogAdapter)1 MatchedEntry (com.tencent.wstt.gt.ui.model.MatchedEntry)1 BufferedReader (java.io.BufferedReader)1 FileInputStream (java.io.FileInputStream)1 InputStreamReader (java.io.InputStreamReader)1 ArrayList (java.util.ArrayList)1