当前位置:网站首页>日志级别 和 打印log注意
日志级别 和 打印log注意
2022-07-31 03:16:00 【喀什葛尔的胡杨_】
常用的日志打印 占位符一般用 {} 就可以, 例如
log.info("name is {}", name);
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class HelloWorld {
public static Log log = LogFactory.getLog(HelloWorld.class);
public static void main(String[] argv) {
String test="sdibt";
log.error("this is error:"+test);
log.info("this is info:"+test);
log.debug("this is debug:"+test);
}
}
日志信息中已经给出了类名,根据类名及打印信息可以直接查找到所在的代码
格式: 时间 info 包名.类型 打印日志所在行数, 打印日志信息
2018-05-10 10:46:29,566 ERROR [example.HelloWorld]:10 - this is error:sdibt
2018-05-10 10:46:29,566 INFO [example.HelloWorld]:11 - this is info:sdibt
2018-05-10 10:46:29,566 DEBUG [example.HelloWorld]:12 - this is debug:sdibt
List<String> 和 Set<String> 可以直接打印, 但List<User> 需要重写User的equals和hashcode方法才可以打印
List<String> list = new ArrayList<>();
list.add("1");
list.add("1" );
log.info("list集合: {}", list); // 结果是 [1, 1]
Set<String> set = new HashSet<>();
set.add("1");
set.add("1" );
log.info("set集合: {}", set); // 结果是 [1]边栏推荐
猜你喜欢

Mysql 45讲学习笔记(二十四)MYSQL主从一致

10 Permission introduction

Addition and Subtraction of Scores in LeetCode Medium Questions

JS function this context runtime syntax parentheses array IIFE timer delay self.backup context call apply

学习DAVID数据库(1)

12 Disk related commands

QML的使用

6. Display comments and replies

Moxa NPort device flaw could expose critical infrastructure to devastating attack

【C语言】三子棋(经典解法+一览图)
随机推荐
Observer pattern
QML的使用
2022牛客多校联赛第四场 题解
CorelDRAW2022 streamlined Asia Pacific new features in detail
注解用法含义
Day32 LeetCode
顺序表的实现
els 方块向左移动条件判断
Chapter 9 SVM Practice
Thesis framework of the opening report
PMP WeChat group daily exercises
【C语言】三子棋(经典解法+一览图)
LeetCode简单题之两个数组间的距离值
【CocosCreator 3.5】CocosCreator get network status
10 Permission introduction
TCP详解(二)
递归查询单表-单表树结构-(自用)
【HCIP】ISIS
WebSocket Session is null
Moxa NPort 设备缺陷可能使关键基础设施遭受破坏性攻击