查看“JUL 硬编码配置”的源代码
←
JUL 硬编码配置
跳到导航
跳到搜索
因为以下原因,您没有权限编辑本页:
您所请求的操作仅限于该用户组的用户使用:
用户
您可以查看和复制此页面的源代码。
https://www.bilibili.com/video/BV1iJ411H74S?p=6 === 代码1 === <syntaxhighlight lang="java"> // 日志级别 @Test public void testLogConfig() { //1、获取日志记录器对象 Logger logger = Logger.getLogger("io.github.jihch.JULTest"); // 关闭系统默认配置 logger.setUseParentHandlers(false); // 创建 ConsolHandler ConsoleHandler consoleHandler = new ConsoleHandler(); // 创建简单格式 SimpleFormatter simpleFormatter = new SimpleFormatter(); // 进行关联 consoleHandler.setFormatter(simpleFormatter); logger.addHandler(consoleHandler); // 配置日志具体级别 logger.setLevel(Level.ALL); consoleHandler.setLevel(Level.ALL); //2、日志记录输出 logger.severe("severe"); logger.warning("warning"); logger.info("info"); logger.config("config"); logger.fine("fine"); logger.finer("finer"); logger.finest("finest"); } </syntaxhighlight><syntaxhighlight lang="console"> 二月 21, 2023 8:55:14 下午 io.github.jihch.JULTest testLogConfig 严重: severe 二月 21, 2023 8:55:14 下午 io.github.jihch.JULTest testLogConfig 警告: warning 二月 21, 2023 8:55:14 下午 io.github.jihch.JULTest testLogConfig 信息: info 二月 21, 2023 8:55:14 下午 io.github.jihch.JULTest testLogConfig 配置: config 二月 21, 2023 8:55:14 下午 io.github.jihch.JULTest testLogConfig 详细: fine 二月 21, 2023 8:55:14 下午 io.github.jihch.JULTest testLogConfig 较详细: finer 二月 21, 2023 8:55:14 下午 io.github.jihch.JULTest testLogConfig 非常详细: finest </syntaxhighlight> === 代码2 === <syntaxhighlight lang="java"> // 日志级别 @Test public void testLogConfig() throws IOException { //1、获取日志记录器对象 Logger logger = Logger.getLogger("io.github.jihch.JULTest"); // 关闭系统默认配置 logger.setUseParentHandlers(false); // 创建 ConsolHandler 控制台输出 ConsoleHandler consoleHandler = new ConsoleHandler(); // 创建简单格式 SimpleFormatter simpleFormatter = new SimpleFormatter(); // 进行关联 consoleHandler.setFormatter(simpleFormatter); logger.addHandler(consoleHandler); // 配置日志具体级别 logger.setLevel(Level.ALL); consoleHandler.setLevel(Level.ALL); // 场景 FileHandler 文件输出 FileHandler fileHandler = new FileHandler("E:\\record\\2023\\2\\21\\jul.log"); // 进行关联 fileHandler.setFormatter(simpleFormatter); logger.addHandler(fileHandler); //2、日志记录输出 logger.severe("severe"); logger.warning("warning"); logger.info("info"); logger.config("config"); logger.fine("fine"); logger.finer("finer"); logger.finest("finest"); } </syntaxhighlight><syntaxhighlight lang="console"> 二月 21, 2023 9:06:53 下午 io.github.jihch.JULTest testLogConfig 严重: severe 二月 21, 2023 9:06:53 下午 io.github.jihch.JULTest testLogConfig 警告: warning 二月 21, 2023 9:06:53 下午 io.github.jihch.JULTest testLogConfig 信息: info 二月 21, 2023 9:06:53 下午 io.github.jihch.JULTest testLogConfig 配置: config 二月 21, 2023 9:06:53 下午 io.github.jihch.JULTest testLogConfig 详细: fine 二月 21, 2023 9:06:53 下午 io.github.jihch.JULTest testLogConfig 较详细: finer 二月 21, 2023 9:06:53 下午 io.github.jihch.JULTest testLogConfig 非常详细: finest </syntaxhighlight>E:\record\2023\2\21\jul.log<syntaxhighlight lang="console"> 二月 21, 2023 9:06:53 下午 io.github.jihch.JULTest testLogConfig 严重: severe 二月 21, 2023 9:06:53 下午 io.github.jihch.JULTest testLogConfig 警告: warning 二月 21, 2023 9:06:53 下午 io.github.jihch.JULTest testLogConfig 信息: info 二月 21, 2023 9:06:53 下午 io.github.jihch.JULTest testLogConfig 配置: config 二月 21, 2023 9:06:53 下午 io.github.jihch.JULTest testLogConfig 详细: fine 二月 21, 2023 9:06:53 下午 io.github.jihch.JULTest testLogConfig 较详细: finer 二月 21, 2023 9:06:53 下午 io.github.jihch.JULTest testLogConfig 非常详细: finest </syntaxhighlight>
返回至
JUL 硬编码配置
。
导航菜单
个人工具
登录
名字空间
页面
讨论
变种
视图
阅读
查看源代码
查看历史
更多
搜索
导航
首页
Spring Boot 2 零基础入门
Spring Cloud
Spring Boot
设计模式之禅
VUE
Vuex
Maven
算法
技能树
Wireshark
IntelliJ IDEA
ElasticSearch
VirtualBox
软考
正则表达式
程序员精讲
软件设计师精讲
初级程序员 历年真题
C
SQL
Java
FFmpeg
Redis
Kafka
MySQL
Spring
Docker
JMeter
Apache
Linux
Windows
Git
ZooKeeper
设计模式
Python
MyBatis
软件
数学
PHP
IntelliJ IDEA
CS基础知识
网络
项目
未分类
MediaWiki
镜像
问题
健身
国债
英语
烹饪
常见术语
MediaWiki帮助
工具
链入页面
相关更改
特殊页面
页面信息