| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- package com.nju.edu.eval.util;
- import com.alibaba.fastjson.JSON;
- import com.alibaba.fastjson.serializer.SerializerFeature;
- import com.nju.edu.eval.data.entity.Exam;
- import com.nju.edu.eval.model.vo.logdata.AnswerDTO;
- import com.nju.edu.eval.model.vo.logdata.ExamLog;
- import com.nju.edu.eval.model.vo.logdata.ExamRecordLog;
- import lombok.extern.slf4j.Slf4j;
- import org.slf4j.Logger;
- import java.util.Date;
- import java.util.List;
- import java.util.stream.Collectors;
- @Slf4j
- public class LogTracingUtil {
- private static final Logger logger = LoggerUtil.getLogger(LogTracingUtil.class);
- public static void logToAnalysis(String data, int type, String message) {
- // // String data = "This is an example";
- //
- // //此为logBuilder,若不想使用也可自己构建log
- // //注:此logBuilder在调用build方法时会自动添加created_time属性,值为当前时间戳
- //
- // String logData = "";
- //
- // try {
- // logData= LogBuilder
- // .getBuilder()
- // .target(SeecSystem.SMART) // 等待分配enum后修改
- // .source(SeecSystem.EVAL)
- // .operationType(type)
- // .data(data)
- // .message(message)
- // .build();
- //
- // //最简单使用方法,默认为medium级别
- // LogTrackingClient
- // .getClient()
- // .log(logData)
- // .publish();
- //
- // // LoggerUtil.info(logger, logData);
- // LoggerUtil.info(logger, "SMART --> " + logData);
- //
- // }catch(Exception e){
- // LoggerUtil.info(logger, "SMART --> " + logData);
- // e.printStackTrace();
- // }
- }
- public static void logExam(Exam exam, int type) {
- // try {
- // List<AnswerDTO> answerDTOS = exam.getQuestionAndScore().entrySet().stream().
- // map(et -> new AnswerDTO(et.getKey(), et.getValue())).collect(Collectors.toList());
- // double totalGrade = exam.getQuestionAndScore().values().stream().collect(Collectors.summarizingInt(x -> x.intValue())).getSum();
- //
- // ExamLog examLog = new ExamLog(exam.getId(), totalGrade, answerDTOS, exam.getDifficulty(), new Date(), exam.getStartTime(), exam.getEndTime());
- //
- // logToAnalysis(JSON.toJSONStringWithDateFormat(examLog, "yyyy-MM-dd HH:mm:ss", SerializerFeature.WriteDateUseDateFormat), type, "exam data");
- // }catch (Exception e){
- // System.out.println("构建日志数据失败");
- // e.printStackTrace();
- // }
- }
- public static void logRecord(ExamRecordLog examRecordLog) {
- // logToAnalysis(JSON.toJSONStringWithDateFormat(examRecordLog, "yyyy-MM-dd HH:mm:ss", SerializerFeature.WriteDateUseDateFormat), 2, "record data");
- }
- public static void logSimple(String log) {
- // logger.info(log);
- }
- }
|