Commit e4eae311 authored by yanzg's avatar yanzg

压缩视频

parent 6e170c8b
......@@ -88,6 +88,7 @@ public class Log {
private static void add(LogInfo info) {
// 获取当前线程编号
String threadId = getThreadId();
info.setThreadId(threadId);
// 判断当前线程日志是否需要特殊处理
LogDate date;
......
package com.yanzuoguang.util.log;
import com.yanzuoguang.util.helper.DateHelper;
import com.yanzuoguang.util.helper.FileHelper;
import com.yanzuoguang.util.helper.StringHelper;
import com.yanzuoguang.util.vo.MapRow;
import java.io.File;
import java.util.Date;
/**
* 日志处理默认处理函数
......@@ -10,6 +15,18 @@ import com.yanzuoguang.util.helper.StringHelper;
*/
public class LogDefault implements RunnableLog {
private static String pathFormat = StringHelper.EMPTY;
public static String getPathFormat() {
return pathFormat;
}
public static void setPathFormat(String pathFormat) {
LogDefault.pathFormat = pathFormat;
}
/**
* 需要处理的日志
*
......@@ -26,23 +43,41 @@ public class LogDefault implements RunnableLog {
clsName = info.getCls().getSimpleName();
}
StringBuilder sb = new StringBuilder(String.format("/* %s pid:%d t:%d/%d ms %s %s */ %s",
DateHelper.getDateTimeString("HH:mm:ss.SSS", info.getNow()),
Thread.currentThread().getId(),
info.getTime(),
info.getTotalTime(),
clsName,
info.getTag(),
info.getMessage()
));
StringBuilder sb = new StringBuilder();
sb.append("/* ");
sb.append(DateHelper.getDateTimeString("HH:mm:ss.SSS", info.getNow()));
sb.append(" pid:");
sb.append(info.getThreadId());
sb.append(" t:");
sb.append(info.getTime());
sb.append(" /");
sb.append(info.getTotalTime());
sb.append(" ms ");
sb.append(clsName);
sb.append(" ");
sb.append(info.getTag());
sb.append(" */ ");
sb.append(info.getMessage());
Throwable ex = info.getException();
if (ex != null) {
sb.append(ex.getClass().getName());
sb.append(ex.getMessage());
System.err.println(sb.toString());
sb.append(System.getProperty("line.separator"));
System.err.print(sb.toString());
ex.printStackTrace();
} else {
System.out.println(sb.toString());
sb.append(System.getProperty("line.separator"));
System.out.print(sb.toString());
}
if (!StringHelper.isEmpty(pathFormat)) {
MapRow row = new MapRow();
row.put("day", DateHelper.getToday(info.getNow()));
row.put("thread", info.getThreadId());
String path = StringHelper.getCodeString(pathFormat, row);
FileHelper.writeFile(new File(path), sb.toString(), "UTF-8");
}
}
}
......@@ -4,6 +4,7 @@ import java.util.Date;
/**
* 日志实体记录类
*
* @author 颜佐光
*/
public class LogInfo {
......@@ -36,6 +37,11 @@ public class LogInfo {
*/
private long totalTime;
/**
* 线程Id
*/
private String threadId;
/**
* 构造函数
*
......@@ -109,19 +115,17 @@ public class LogInfo {
}
public Date getNow() {
if(this.now == 0){
if (this.now == 0) {
return null;
}
else{
} else {
return new Date(this.now);
}
}
public void setNow(Date now) {
if(now != null){
this.now = now.getTime() ;
}
else{
if (now != null) {
this.now = now.getTime();
} else {
this.now = 0;
}
}
......@@ -165,4 +169,12 @@ public class LogInfo {
public void setTotalTime(long totalTime) {
this.totalTime = totalTime;
}
public String getThreadId() {
return threadId;
}
public void setThreadId(String threadId) {
this.threadId = threadId;
}
}
package log;
import com.yanzuoguang.util.log.Log;
import com.yanzuoguang.util.log.LogDefault;
import com.yanzuoguang.util.thread.RunnableListAuto;
import org.junit.Test;
public class TestByteHelper {
@Test
public void test() {
LogDefault.setPathFormat("/home/yanzuoguang/log/{day}/{thread}.log");
RunnableListAuto.run(new Runnable() {
@Override
public void run() {
Log.info(TestByteHelper.class, "等待2秒秒");
}
}, new Runnable() {
@Override
public void run() {
Log.info(TestByteHelper.class, "等待2秒秒");
}
});
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment