Commit e4eae311 authored by yanzg's avatar yanzg

压缩视频

parent 6e170c8b
...@@ -88,6 +88,7 @@ public class Log { ...@@ -88,6 +88,7 @@ public class Log {
private static void add(LogInfo info) { private static void add(LogInfo info) {
// 获取当前线程编号 // 获取当前线程编号
String threadId = getThreadId(); String threadId = getThreadId();
info.setThreadId(threadId);
// 判断当前线程日志是否需要特殊处理 // 判断当前线程日志是否需要特殊处理
LogDate date; LogDate date;
......
package com.yanzuoguang.util.log; package com.yanzuoguang.util.log;
import com.yanzuoguang.util.helper.DateHelper; import com.yanzuoguang.util.helper.DateHelper;
import com.yanzuoguang.util.helper.FileHelper;
import com.yanzuoguang.util.helper.StringHelper; 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; ...@@ -10,6 +15,18 @@ import com.yanzuoguang.util.helper.StringHelper;
*/ */
public class LogDefault implements RunnableLog { 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 { ...@@ -26,23 +43,41 @@ public class LogDefault implements RunnableLog {
clsName = info.getCls().getSimpleName(); clsName = info.getCls().getSimpleName();
} }
StringBuilder sb = new StringBuilder(String.format("/* %s pid:%d t:%d/%d ms %s %s */ %s", StringBuilder sb = new StringBuilder();
DateHelper.getDateTimeString("HH:mm:ss.SSS", info.getNow()), sb.append("/* ");
Thread.currentThread().getId(), sb.append(DateHelper.getDateTimeString("HH:mm:ss.SSS", info.getNow()));
info.getTime(), sb.append(" pid:");
info.getTotalTime(), sb.append(info.getThreadId());
clsName, sb.append(" t:");
info.getTag(), sb.append(info.getTime());
info.getMessage() 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(); Throwable ex = info.getException();
if (ex != null) { if (ex != null) {
sb.append(ex.getClass().getName()); sb.append(ex.getClass().getName());
sb.append(ex.getMessage()); sb.append(ex.getMessage());
System.err.println(sb.toString()); sb.append(System.getProperty("line.separator"));
System.err.print(sb.toString());
ex.printStackTrace(); ex.printStackTrace();
} else { } 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; ...@@ -4,6 +4,7 @@ import java.util.Date;
/** /**
* 日志实体记录类 * 日志实体记录类
*
* @author 颜佐光 * @author 颜佐光
*/ */
public class LogInfo { public class LogInfo {
...@@ -36,6 +37,11 @@ public class LogInfo { ...@@ -36,6 +37,11 @@ public class LogInfo {
*/ */
private long totalTime; private long totalTime;
/**
* 线程Id
*/
private String threadId;
/** /**
* 构造函数 * 构造函数
* *
...@@ -109,19 +115,17 @@ public class LogInfo { ...@@ -109,19 +115,17 @@ public class LogInfo {
} }
public Date getNow() { public Date getNow() {
if(this.now == 0){ if (this.now == 0) {
return null; return null;
} } else {
else{
return new Date(this.now); return new Date(this.now);
} }
} }
public void setNow(Date now) { public void setNow(Date now) {
if(now != null){ if (now != null) {
this.now = now.getTime() ; this.now = now.getTime();
} } else {
else{
this.now = 0; this.now = 0;
} }
} }
...@@ -165,4 +169,12 @@ public class LogInfo { ...@@ -165,4 +169,12 @@ public class LogInfo {
public void setTotalTime(long totalTime) { public void setTotalTime(long totalTime) {
this.totalTime = 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