当前位置:网站首页>日志级别 和 打印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]
边栏推荐
- 想从手工测试转岗自动化测试,需要学习哪些技能?
- Crypto Firms Offer Offer To Theft Hackers: Keep A Little, Give The Rest
- 【Cocos Creator 3.5】缓动系统停止所有动画
- What is SQALE
- some of my own thoughts
- LeetCode simple problem to find the subsequence of length K with the largest sum
- [Dynamic programming] Maximum sum of consecutive subarrays
- 品牌广告投放平台的中台化应用与实践
- SQL injection Less47 (error injection) and Less49 (time blind injection)
- C#远程调试
猜你喜欢
随机推荐
BUG definition of SonarQube
Day32 LeetCode
Golang中的addressable
下载jar包的好地方
CloudCompare&PCL 计算两个点云之间的重叠度
WebSocket Session is null
SQL 面试用题(重点)
[Android] Room - Alternative to SQLite
【异常】The field file exceeds its maximum permitted size of 1048576 bytes.
CorelDRAW2022 streamlined Asia Pacific new features in detail
Database implements distributed locks
CloudCompare & PCL calculate the degree of overlap between two point clouds
8. Unified exception handling (controller notifies @ControllerAdvice global configuration class, @ExceptionHandler handles exceptions uniformly)
2022 Nioke Multi-School League Game 4 Solution
MultipartFile文件上传
some of my own thoughts
IDEA 注释报红解决
Unity3D Button mouse hover enter and mouse hover exit button events
STM32 problem collection
Discourse Custom Header Links