Search in sources :

Example 1 with LogResult

use of com.xxl.job.core.biz.model.LogResult in project xxl-job by xuxueli.

the class ExecutorBizImpl method log.

@Override
public ReturnT<LogResult> log(long logDateTim, int logId, int fromLineNum) {
    // log filename: logPath/yyyy-MM-dd/9999.log
    String logFileName = XxlJobFileAppender.makeLogFileName(new Date(logDateTim), logId);
    LogResult logResult = XxlJobFileAppender.readLog(logFileName, fromLineNum);
    return new ReturnT<LogResult>(logResult);
}
Also used : LogResult(com.xxl.job.core.biz.model.LogResult) ReturnT(com.xxl.job.core.biz.model.ReturnT) Date(java.util.Date)

Example 2 with LogResult

use of com.xxl.job.core.biz.model.LogResult in project xxl-job by xuxueli.

the class XxlJobFileAppender method readLog.

/**
 * support read log-file
 *
 * @param logFileName
 * @return log content
 */
public static LogResult readLog(String logFileName, int fromLineNum) {
    // valid log file
    if (logFileName == null || logFileName.trim().length() == 0) {
        return new LogResult(fromLineNum, 0, "readLog fail, logFile not found", true);
    }
    File logFile = new File(logFileName);
    if (!logFile.exists()) {
        return new LogResult(fromLineNum, 0, "readLog fail, logFile not exists", true);
    }
    // read file
    StringBuffer logContentBuffer = new StringBuffer();
    int toLineNum = 0;
    LineNumberReader reader = null;
    try {
        // reader = new LineNumberReader(new FileReader(logFile));
        reader = new LineNumberReader(new InputStreamReader(new FileInputStream(logFile), "utf-8"));
        String line = null;
        while ((line = reader.readLine()) != null) {
            // [from, to], start as 1
            toLineNum = reader.getLineNumber();
            if (toLineNum >= fromLineNum) {
                logContentBuffer.append(line).append("\n");
            }
        }
    } catch (IOException e) {
        logger.error(e.getMessage(), e);
    } finally {
        if (reader != null) {
            try {
                reader.close();
            } catch (IOException e) {
                logger.error(e.getMessage(), e);
            }
        }
    }
    // result
    LogResult logResult = new LogResult(fromLineNum, toLineNum, logContentBuffer.toString(), false);
    return logResult;
/*
        // it will return the number of characters actually skipped
        reader.skip(Long.MAX_VALUE);
        int maxLineNum = reader.getLineNumber();
        maxLineNum++;	// 最大行号
        */
}
Also used : LogResult(com.xxl.job.core.biz.model.LogResult)

Example 3 with LogResult

use of com.xxl.job.core.biz.model.LogResult in project xxl-job by xuxueli.

the class JobLogController method logDetailCat.

@RequestMapping("/logDetailCat")
@ResponseBody
public ReturnT<LogResult> logDetailCat(String executorAddress, long triggerTime, int logId, int fromLineNum) {
    try {
        ExecutorBiz executorBiz = XxlJobDynamicScheduler.getExecutorBiz(executorAddress);
        ReturnT<LogResult> logResult = executorBiz.log(triggerTime, logId, fromLineNum);
        // is end
        if (logResult.getContent() != null && logResult.getContent().getFromLineNum() > logResult.getContent().getToLineNum()) {
            XxlJobLog jobLog = xxlJobLogDao.load(logId);
            if (jobLog.getHandleCode() > 0) {
                logResult.getContent().setEnd(true);
            }
        }
        return logResult;
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        return new ReturnT<LogResult>(ReturnT.FAIL_CODE, e.getMessage());
    }
}
Also used : ExecutorBiz(com.xxl.job.core.biz.ExecutorBiz) LogResult(com.xxl.job.core.biz.model.LogResult) XxlJobLog(com.xxl.job.admin.core.model.XxlJobLog) ParseException(java.text.ParseException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

LogResult (com.xxl.job.core.biz.model.LogResult)3 XxlJobLog (com.xxl.job.admin.core.model.XxlJobLog)1 ExecutorBiz (com.xxl.job.core.biz.ExecutorBiz)1 ReturnT (com.xxl.job.core.biz.model.ReturnT)1 ParseException (java.text.ParseException)1 Date (java.util.Date)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1