tinylog || Log4j 、Logback 替代品
程序员的成长之路
共 4470字,需浏览 9分钟
·
2022-01-01 19:42
阅读本文大概需要 4 分钟。
来自:blog.csdn.net/cunchi4221/article/details/107477602
tinylog-api-2.0.0-RC1.jar
tinylog-impl-2.0.0-RC1.jar
<dependency>
<groupId>org.tinyloggroupId>
<artifactId>tinylog-apiartifactId>
<version>2.0.0-RC1version>
dependency>
<dependency>
<groupId>org.tinyloggroupId>
<artifactId>tinylog-implartifactId>
<version>2.0.0-RC1version>
dependency>
implementation 'org.tinylog:tinylog-api:2.0.0-RC1'
implementation 'org.tinylog:tinylog-impl:2.0.0-RC1'
package com.journaldev.tinylog;
import org.tinylog.Logger;
public class Employee {
private int id;
private String name;
public String getName() {
Logger.debug("Returning employee name " + this.name);
return name;
}
public void setName(String name) {
Logger.info("Setting employee name " + name);
this.name = name;
}
public int getId() {
Logger.debug("Returning employee id " + this.id);
return id;
}
public void setId(int id) {
Logger.info("Setting employee id " + id);
this.id = id;
}
}
package com.journaldev.tinylog;
import org.tinylog.Logger;
public class EmployeeService {
public Employee createEmployee(int i, String n) {
Logger.info("Creating Employee with ID = " + i + " and Name = " + n);
Employee emp = new Employee();
emp.setId(i);
emp.setName(n);
return emp;
}
}
package com.journaldev.tinylog;
import org.tinylog.Logger;
public class EmployeeMain {
public static void main(String[] args) {
Logger.debug("Program Started");
EmployeeService empService = new EmployeeService();
Employee emp = empService.createEmployee(10, "Pankaj");
System.out.println("Employee ID = " + emp.getId());
System.out.println("Employee Name = " + emp.getName());
Logger.debug("Program Finished");
}
}
writer = console
writer.format = {date: HH:mm:ss.SSS} {tag} {level}: {message}
12:22:47.073 DEBUG: Program Started
12:22:47.076 INFO: Creating Employee with ID = 10 and Name = Pankaj
12:22:47.076 INFO: Setting employee id 10
12:22:47.077 INFO: Setting employee name Pankaj
12:22:47.077 DEBUG: Returning employee id 10
Employee ID = 10
12:22:47.077 DEBUG: Returning employee name Pankaj
Employee Name = Pankaj
12:22:47.077 DEBUG: Program Finished
Logger.tag("MAIN").debug("Program Started");
Logger.tag("MAIN").debug("Program Finished");
12:26:12.831 MAIN DEBUG: Program Started
...
12:26:12.835 MAIN DEBUG: Program Finished
writer = console
writer.tag = SYSTEM
writer = console
writer.tag = -
writer = file
writer.file = tinylog.txt
writer.level = info
writer.format = {date: HH:mm:ss.SSS} {tag} {level}: {message}
writer.file = ${HOME}/tinylog.txt
writer.format = #{user.name}: {message}
writer = rolling file
writer.file = tinylog{count}.txt
writer.level = info
writer.format = {date: HH:mm:ss.SSS} {tag} {level}: {message}
推荐阅读:
Spring Boot 监听 Redis Key 失效事件实现定时任务
内容包含Java基础、JavaWeb、MySQL性能优化、JVM、锁、百万并发、消息队列、高性能缓存、反射、Spring全家桶原理、微服务、Zookeeper、数据结构、限流熔断降级......等技术栈!
⬇戳阅读原文领取! 朕已阅
评论