简要说明:
现在日志输出框架太多,想找个简单的用用,结果没找到.日志输出中又不想做任何依赖处理,所以就自己做了一个日志输出.完整代码如下:
package com.liangchao.luckdraw.netty;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* 用户自定义日志输出,支持控制台输出, 文件输出,全输出. 不依赖其他依赖包.
*
* @Author: 超哥分享
* @Email: 245073271@qq.com
* @Description: 其他用户转载请添加原始链接, 否则侵权.亲尊重劳动成果, 交流建议请联系本人.谢谢你的支持.
*/
public class Logs {
private String filePath = "./";//文件保存路径
private String fileName = "logs.log";//文件名称
private Integer maxFileSize = 1024 * 1024 * 10;//文件分割大小
private String outStrPrefix = "❖☛";//输出前缀
private Boolean isConsoleMode = false;//控制台模式
private LogsType logsType = LogsType.FILE;//输出位置
private LogsLevel logsLevel = LogsLevel.INFO;//输出级别
private String dateFormatStr = "yyyy-MM-dd HH:mm:ss";//日期格式化
private SimpleDateFormat dateFormat;//日期格式化
private StringBuffer msgCacheData = new StringBuffer();//日志信息缓存容器
private long readSize = 1024;//写入文件更新数据限制大小
/**
* 默认模式
*/
public Logs() {
init();
}
/**
* 文件变更模式
*/
public Logs(String filePath, String fileName) {
this(filePath, fileName, null, null, null, null, null, null);
}
/** 输出变更模式 **/
public Logs(LogsType logsType, LogsLevel logsLevel) {
this(null, null, null, null, null, logsType, logsLevel, null);
}
/**
* 文件 输出变更模式
*/
public Logs(String filePath, String fileName, LogsType logsType, LogsLevel logsLevel) {
this(filePath, fileName, null, null, null, logsType, logsLevel, null);
}
/**
* 自定义日志 (全参数)
*
* @param filePath 文件路径
* @param fileName 文件名称
* @param maxFileSize 文件分割块大小
* @param outStrPrefix 控制台模式输出前缀
* @param isConsoleMode 控制台模式:true 控制台方式, false:通常日志输出格式
* @param logsType 输出日志类型
* @param logsLevel 输出日志级别
* @param dateFormatStr 日期时间戳格式化
*/
public Logs(String filePath, String fileName, Integer maxFileSize, String outStrPrefix, Boolean isConsoleMode, LogsType logsType, LogsLevel logsLevel, String dateFormatStr) {
if (filePath != null) {
this.filePath = filePath;
}
if (fileName != null) {
this.fileName = fileName;
}
if (maxFileSize != null) {
this.maxFileSize = maxFileSize;
}
if (outStrPrefix != null) {
this.outStrPrefix = outStrPrefix;
}
if (isConsoleMode != null) {
this.isConsoleMode = isConsoleMode;
}
if (logsType != null) {
this.logsType = logsType;
}
if (logsLevel != null) {
this.logsLevel = logsLevel;
}
if (dateFormatStr != null) {
this.dateFormatStr = dateFormatStr;
}
init();
}
/**
* 允许操作输出处理
*/
public boolean allow(LogsLevel logsLevel) {
// @formatter:off
if ((this.logsLevel.equals(LogsLevel.INFO) && logsLevel.equals(LogsLevel.INFO) ) ||
(this.logsLevel.equals(LogsLevel.DEBUG) && (logsLevel.equals(LogsLevel.INFO) || logsLevel.equals(LogsLevel.DEBUG))) ||
this.logsLevel.equals(LogsLevel.ERROR)
) {
// @formatter:on
return true;
}
else {
return false;
}
}
/**
* debug 输出
*
* @param msg 输出数据
*/
public void debug(Object msg) {
write(LogsLevel.DEBUG, msg);
}
/**
* error 输出
*
* @param msg 输出数据
*/
public void error(Object msg) {
write(LogsLevel.ERROR, msg);
}
/**
* 执行写入日志操作
*/
private void executeReadFile() throws IOException {
String path = filePath + fileName;
if (path == null || path.isEmpty()) {
throw new LogException("文件路径无效");
}
File file = new File(path);
//文件切片处理
if (file.exists() && file.length() >= maxFileSize) {
int index = file.getParentFile().listFiles().length + 1;
String newPath = filePath + fileName.substring(0, fileName.indexOf(".")) + new SimpleDateFormat("yyyy-MM-dd").format(new Date()) + "-" + index + ".log";
file.renameTo(new File(newPath));
}
if (!file.exists()) {
if (!file.getParentFile().exists()) {
file.getParentFile().mkdirs();
}
file.createNewFile();
}
//写入数据
BufferedWriter writer = new BufferedWriter(new FileWriter(file, true));
writer.append(msgCacheData.toString());
writer.flush();
writer.close();
file = null;
writer = null;
//清空数据
msgCacheData.setLength(0);
}
/**
* 类路径显示首字母缩写
*
* @param classPath 类路径
*/
public String format(String classPath) {
if (classPath == null || classPath.isEmpty()) {
return null;
}
String newStr = "";
String[] split = classPath.split("\\.");
for (int i = 0; i < split.length; i++) {
if (i == split.length - 1) {
newStr += "." + split[i];
}
else {
newStr += "." + split[i].charAt(0);
}
}
return newStr != "" && newStr.length() > 0 ? newStr.substring(1) : null;
}
/**
* 获取:类名(首字母缩写);方法名;执行行号
*/
public String getClassInfo() {
StackTraceElement[] stackTraceElements = new Throwable().getStackTrace();
int index = 3;
if (stackTraceElements.length >= index) {
// @formatter:off
return String.format("[%-20s][%-10s][%-5d]",
format(stackTraceElements[index].getClassName()),
stackTraceElements[index].getMethodName(),
stackTraceElements[index].getLineNumber()
);
// @formatter:on
}
else {
return null;
}
}
/**
* info 输出
*
* @param msg 输出数据
*/
public void info(Object msg) {
write(LogsLevel.INFO, msg);
}
/**
* 初始化数
*/
private void init() {
dateFormat = new SimpleDateFormat(dateFormatStr);
if (logsType.equals(LogsType.FILE)) {
//注册关闭处理事件
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
try {
executeReadFile();
} catch (IOException e) {
e.printStackTrace();
}
}
});
}
}
/**
* 添加日志文件信息, 达到readSize 限制后写入数据(同步)
*/
private synchronized void readFile(Object msg) {
msgCacheData.append(msg);
if (msgCacheData.length() >= readSize) {
try {
executeReadFile();
} catch (IOException e) {
e.printStackTrace();
}
}
}
/**
* 输出到文件
*
* @param logsLevel 级别
* @param str 信息
*/
private void write(LogsLevel logsLevel, Object str) {
//当单次数据超过分块大小 异常
if (this.logsType.equals(LogsType.FILE) && str.toString().length() > this.maxFileSize) {
throw new LogException("单次输出数据超出文件分块大小:" + this.maxFileSize);
}
String msg;
//控制台模式
if (isConsoleMode) {
msg = String.format("%-3s%s\n", outStrPrefix, str);
}
else {
// @formatter:off
msg = String.format("[%s] [%-5s] %-40s:%s\n",
dateFormat.format(new Date()),
logsLevel.name().toUpperCase(),
getClassInfo(),
str
);
// @formatter:on
}
if (logsType.equals(LogsType.CONSOLE) || logsType.equals(LogsType.ALL)) {
if (allow(logsLevel)) {
System.out.print(msg);
}
}
if (logsType.equals(LogsType.FILE) || logsType.equals(LogsType.ALL)) {
if (allow(logsLevel)) {
readFile(msg);
}
}
}
/**
* 输出级别
*/
public enum LogsLevel {
/** INFO **/
INFO,
/** DEBUG **/
DEBUG,
/** ERROR **/
ERROR;
}
/**
* 输出类型
*/
public enum LogsType {
/**
* 控制台
*/
CONSOLE,
/**
* 文件
*/
FILE,
/**
* 全部
*/
ALL,
}
/**
* 日志异常
*/
public class LogException extends RuntimeException {
public LogException() {
}
public LogException(String message) {
super(message);
}
public LogException(String message, Throwable cause) {
super(message, cause);
}
public LogException(Throwable cause) {
super(cause);
}
}
}
测试代码:
/**
* 测试
*/
@Deprecated
public static void main(String[] args) {
Logs logs;
//默认模式
logs = new Logs();
//文件变更模式
//logs = new Logs("c:\\", "xp.log");
//输出变更模式
//logs = new Logs(LogsType.ALL, LogsLevel.INFO);
//文件 输出变更模式
//logs = new Logs("c:\\", "xp.log", LogsType.CONSOLE, LogsLevel.ERROR);
//全参数
//logs = new Logs("c:\\", "xp1.log", 1024 * 1024, ">", false, LogsType.FILE, LogsLevel.ERROR, "yy-MM-dd");
//Logs logs = new Logs("./logs/");
int i = 0;
while (i < 10000) {
logs.info("我是测试数据1." + i);
logs.debug("我是测试数据2." + i);
logs.error("我是测试数据3." + i);
i++;
}
}
输出效果展示
1. 控制台输出
1.格式一
"C:\Program Files\Java\jdk1.8.0_201\bin\java.exe" "-javaagent:C:\JetBrains\IntelliJ IDEA 2019.3\lib\idea_rt.jar=55109:C:\JetBrains\IntelliJ IDEA 2019.3\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.8.0_201\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\rt.jar;C:\Users\Administrator\ConceptWork\LuckDraw\luckdraw-netty\target\classes;C:\MavenLibDB\com\esotericsoftware\kryo\5.0.0-RC5\kryo-5.0.0-RC5.jar;C:\MavenLibDB\com\esotericsoftware\reflectasm\1.11.8\reflectasm-1.11.8.jar;C:\MavenLibDB\org\objenesis\objenesis\3.0.1\objenesis-3.0.1.jar;C:\MavenLibDB\com\esotericsoftware\minlog\1.3.1\minlog-1.3.1.jar;C:\MavenLibDB\io\netty\netty-all\4.1.45.Final\netty-all-4.1.45.Final.jar;C:\MavenLibDB\org\projectlombok\lombok\1.18.12\lombok-1.18.12.jar" com.liangchao.luckdraw.netty.Logs
[2020-04-23 15:25:08] [INFO ] [c.l.l.n.Logs ][main ][117 ]:我是测试数据1.0
[2020-04-23 15:25:08] [INFO ] [c.l.l.n.Logs ][main ][117 ]:我是测试数据1.1
[2020-04-23 15:25:08] [INFO ] [c.l.l.n.Logs ][main ][117 ]:我是测试数据1.2
[2020-04-23 15:25:08] [INFO ] [c.l.l.n.Logs ][main ][117 ]:我是测试数据1.3
[2020-04-23 15:25:08] [INFO ] [c.l.l.n.Logs ][main ][117 ]:我是测试数据1.4
[2020-04-23 15:25:08] [INFO ] [c.l.l.n.Logs ][main ][117 ]:我是测试数据1.5
[2020-04-23 15:25:08] [INFO ] [c.l.l.n.Logs ][main ][117 ]:我是测试数据1.6
[2020-04-23 15:25:08] [INFO ] [c.l.l.n.Logs ][main ][117 ]:我是测试数据1.7
[2020-04-23 15:25:08] [INFO ] [c.l.l.n.Logs ][main ][117 ]:我是测试数据1.8
[2020-04-23 15:25:08] [INFO ] [c.l.l.n.Logs ][main ][117 ]:我是测试数据1.9
Process finished with exit code 0
2.格式二
"C:\Program Files\Java\jdk1.8.0_201\bin\java.exe" "-javaagent:C:\JetBrains\IntelliJ IDEA 2019.3\lib\idea_rt.jar=55122:C:\JetBrains\IntelliJ IDEA 2019.3\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.8.0_201\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\rt.jar;C:\Users\Administrator\ConceptWork\LuckDraw\luckdraw-netty\target\classes;C:\MavenLibDB\com\esotericsoftware\kryo\5.0.0-RC5\kryo-5.0.0-RC5.jar;C:\MavenLibDB\com\esotericsoftware\reflectasm\1.11.8\reflectasm-1.11.8.jar;C:\MavenLibDB\org\objenesis\objenesis\3.0.1\objenesis-3.0.1.jar;C:\MavenLibDB\com\esotericsoftware\minlog\1.3.1\minlog-1.3.1.jar;C:\MavenLibDB\io\netty\netty-all\4.1.45.Final\netty-all-4.1.45.Final.jar;C:\MavenLibDB\org\projectlombok\lombok\1.18.12\lombok-1.18.12.jar" com.liangchao.luckdraw.netty.Logs
[2020-04-23 15:25:57] [INFO ] [c.l.l.n.Logs ][main ][117 ]:我是测试数据1.0
[2020-04-23 15:25:57] [DEBUG] [c.l.l.n.Logs ][main ][118 ]:我是测试数据2.0
[2020-04-23 15:25:57] [INFO ] [c.l.l.n.Logs ][main ][117 ]:我是测试数据1.1
[2020-04-23 15:25:57] [DEBUG] [c.l.l.n.Logs ][main ][118 ]:我是测试数据2.1
[2020-04-23 15:25:57] [INFO ] [c.l.l.n.Logs ][main ][117 ]:我是测试数据1.2
[2020-04-23 15:25:57] [DEBUG] [c.l.l.n.Logs ][main ][118 ]:我是测试数据2.2
[2020-04-23 15:25:57] [INFO ] [c.l.l.n.Logs ][main ][117 ]:我是测试数据1.3
[2020-04-23 15:25:57] [DEBUG] [c.l.l.n.Logs ][main ][118 ]:我是测试数据2.3
[2020-04-23 15:25:57] [INFO ] [c.l.l.n.Logs ][main ][117 ]:我是测试数据1.4
[2020-04-23 15:25:57] [DEBUG] [c.l.l.n.Logs ][main ][118 ]:我是测试数据2.4
[2020-04-23 15:25:57] [INFO ] [c.l.l.n.Logs ][main ][117 ]:我是测试数据1.5
[2020-04-23 15:25:57] [DEBUG] [c.l.l.n.Logs ][main ][118 ]:我是测试数据2.5
[2020-04-23 15:25:57] [INFO ] [c.l.l.n.Logs ][main ][117 ]:我是测试数据1.6
[2020-04-23 15:25:57] [DEBUG] [c.l.l.n.Logs ][main ][118 ]:我是测试数据2.6
[2020-04-23 15:25:57] [INFO ] [c.l.l.n.Logs ][main ][117 ]:我是测试数据1.7
[2020-04-23 15:25:57] [DEBUG] [c.l.l.n.Logs ][main ][118 ]:我是测试数据2.7
[2020-04-23 15:25:57] [INFO ] [c.l.l.n.Logs ][main ][117 ]:我是测试数据1.8
[2020-04-23 15:25:57] [DEBUG] [c.l.l.n.Logs ][main ][118 ]:我是测试数据2.8
[2020-04-23 15:25:57] [INFO ] [c.l.l.n.Logs ][main ][117 ]:我是测试数据1.9
[2020-04-23 15:25:57] [DEBUG] [c.l.l.n.Logs ][main ][118 ]:我是测试数据2.9
Process finished with exit code 0
3.格式三
"C:\Program Files\Java\jdk1.8.0_201\bin\java.exe" "-javaagent:C:\JetBrains\IntelliJ IDEA 2019.3\lib\idea_rt.jar=55135:C:\JetBrains\IntelliJ IDEA 2019.3\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.8.0_201\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\rt.jar;C:\Users\Administrator\ConceptWork\LuckDraw\luckdraw-netty\target\classes;C:\MavenLibDB\com\esotericsoftware\kryo\5.0.0-RC5\kryo-5.0.0-RC5.jar;C:\MavenLibDB\com\esotericsoftware\reflectasm\1.11.8\reflectasm-1.11.8.jar;C:\MavenLibDB\org\objenesis\objenesis\3.0.1\objenesis-3.0.1.jar;C:\MavenLibDB\com\esotericsoftware\minlog\1.3.1\minlog-1.3.1.jar;C:\MavenLibDB\io\netty\netty-all\4.1.45.Final\netty-all-4.1.45.Final.jar;C:\MavenLibDB\org\projectlombok\lombok\1.18.12\lombok-1.18.12.jar" com.liangchao.luckdraw.netty.Logs
[2020-04-23 15:26:46] [INFO ] [c.l.l.n.Logs ][main ][117 ]:我是测试数据1.0
[2020-04-23 15:26:46] [DEBUG] [c.l.l.n.Logs ][main ][118 ]:我是测试数据2.0
[2020-04-23 15:26:46] [ERROR] [c.l.l.n.Logs ][main ][119 ]:我是测试数据3.0
[2020-04-23 15:26:46] [INFO ] [c.l.l.n.Logs ][main ][117 ]:我是测试数据1.1
[2020-04-23 15:26:46] [DEBUG] [c.l.l.n.Logs ][main ][118 ]:我是测试数据2.1
[2020-04-23 15:26:46] [ERROR] [c.l.l.n.Logs ][main ][119 ]:我是测试数据3.1
[2020-04-23 15:26:46] [INFO ] [c.l.l.n.Logs ][main ][117 ]:我是测试数据1.2
[2020-04-23 15:26:46] [DEBUG] [c.l.l.n.Logs ][main ][118 ]:我是测试数据2.2
[2020-04-23 15:26:46] [ERROR] [c.l.l.n.Logs ][main ][119 ]:我是测试数据3.2
[2020-04-23 15:26:46] [INFO ] [c.l.l.n.Logs ][main ][117 ]:我是测试数据1.3
[2020-04-23 15:26:46] [DEBUG] [c.l.l.n.Logs ][main ][118 ]:我是测试数据2.3
[2020-04-23 15:26:46] [ERROR] [c.l.l.n.Logs ][main ][119 ]:我是测试数据3.3
[2020-04-23 15:26:46] [INFO ] [c.l.l.n.Logs ][main ][117 ]:我是测试数据1.4
[2020-04-23 15:26:46] [DEBUG] [c.l.l.n.Logs ][main ][118 ]:我是测试数据2.4
[2020-04-23 15:26:46] [ERROR] [c.l.l.n.Logs ][main ][119 ]:我是测试数据3.4
[2020-04-23 15:26:46] [INFO ] [c.l.l.n.Logs ][main ][117 ]:我是测试数据1.5
[2020-04-23 15:26:46] [DEBUG] [c.l.l.n.Logs ][main ][118 ]:我是测试数据2.5
[2020-04-23 15:26:46] [ERROR] [c.l.l.n.Logs ][main ][119 ]:我是测试数据3.5
[2020-04-23 15:26:46] [INFO ] [c.l.l.n.Logs ][main ][117 ]:我是测试数据1.6
[2020-04-23 15:26:46] [DEBUG] [c.l.l.n.Logs ][main ][118 ]:我是测试数据2.6
[2020-04-23 15:26:46] [ERROR] [c.l.l.n.Logs ][main ][119 ]:我是测试数据3.6
[2020-04-23 15:26:46] [INFO ] [c.l.l.n.Logs ][main ][117 ]:我是测试数据1.7
[2020-04-23 15:26:46] [DEBUG] [c.l.l.n.Logs ][main ][118 ]:我是测试数据2.7
[2020-04-23 15:26:46] [ERROR] [c.l.l.n.Logs ][main ][119 ]:我是测试数据3.7
[2020-04-23 15:26:46] [INFO ] [c.l.l.n.Logs ][main ][117 ]:我是测试数据1.8
[2020-04-23 15:26:46] [DEBUG] [c.l.l.n.Logs ][main ][118 ]:我是测试数据2.8
[2020-04-23 15:26:46] [ERROR] [c.l.l.n.Logs ][main ][119 ]:我是测试数据3.8
[2020-04-23 15:26:46] [INFO ] [c.l.l.n.Logs ][main ][117 ]:我是测试数据1.9
[2020-04-23 15:26:46] [DEBUG] [c.l.l.n.Logs ][main ][118 ]:我是测试数据2.9
[2020-04-23 15:26:46] [ERROR] [c.l.l.n.Logs ][main ][119 ]:我是测试数据3.9
Process finished with exit code 0
- 控制台模式
"C:\Program Files\Java\jdk1.8.0_201\bin\java.exe" "-javaagent:C:\JetBrains\IntelliJ IDEA 2019.3\lib\idea_rt.jar=55166:C:\JetBrains\IntelliJ IDEA 2019.3\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.8.0_201\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\rt.jar;C:\Users\Administrator\ConceptWork\LuckDraw\luckdraw-netty\target\classes;C:\MavenLibDB\com\esotericsoftware\kryo\5.0.0-RC5\kryo-5.0.0-RC5.jar;C:\MavenLibDB\com\esotericsoftware\reflectasm\1.11.8\reflectasm-1.11.8.jar;C:\MavenLibDB\org\objenesis\objenesis\3.0.1\objenesis-3.0.1.jar;C:\MavenLibDB\com\esotericsoftware\minlog\1.3.1\minlog-1.3.1.jar;C:\MavenLibDB\io\netty\netty-all\4.1.45.Final\netty-all-4.1.45.Final.jar;C:\MavenLibDB\org\projectlombok\lombok\1.18.12\lombok-1.18.12.jar" com.liangchao.luckdraw.netty.Logs
❖☛ 我是测试数据1.0
❖☛ 我是测试数据2.0
❖☛ 我是测试数据3.0
❖☛ 我是测试数据1.1
❖☛ 我是测试数据2.1
❖☛ 我是测试数据3.1
❖☛ 我是测试数据1.2
❖☛ 我是测试数据2.2
❖☛ 我是测试数据3.2
❖☛ 我是测试数据1.3
❖☛ 我是测试数据2.3
❖☛ 我是测试数据3.3
❖☛ 我是测试数据1.4
❖☛ 我是测试数据2.4
❖☛ 我是测试数据3.4
❖☛ 我是测试数据1.5
❖☛ 我是测试数据2.5
❖☛ 我是测试数据3.5
❖☛ 我是测试数据1.6
❖☛ 我是测试数据2.6
❖☛ 我是测试数据3.6
❖☛ 我是测试数据1.7
❖☛ 我是测试数据2.7
❖☛ 我是测试数据3.7
❖☛ 我是测试数据1.8
❖☛ 我是测试数据2.8
❖☛ 我是测试数据3.8
❖☛ 我是测试数据1.9
❖☛ 我是测试数据2.9
❖☛ 我是测试数据3.9
Process finished with exit code 0
2. 文件模式输出
3. 文件,控制台模式输出
控制台输出日志信息与日志保存到文件两者并存.不在做多说明.