log4j

Logback源码分析

一曲冷凌霜 提交于 2020-01-20 03:32:43
在日常开发中经常通过打印日志记录程序执行的步骤或者排查问题,如下代码类似很多,但是,它是如何执行的呢? package chapters; import org.slf4j.Logger; import org.slf4j.LoggerFactory; // 省略... Logger logger = LoggerFactory.getLogger(LogbackTest.class); logger.info(" {} is best player in world", "Greizmann"); 本文以Logback日志框架来分析以上代码的实现。 slf4j 如今日志框架常用的有log4j、log4j2、jul(common-log)以及logback。假如项目中用的是jul,如今想改成用log4j,如果直接引用java.util.logging包中Logger,需要修改大量代码,为了解决这个麻烦的事情,Ceki Gülcü 大神开发了slf4j(Simple Logging Facade for Java) 。slf4j 是众多日志框架抽象的门面接口,有了slf4j 想要切换日志实现,只需要把对应日志jar替换和添加对应的适配器。 从图中就可以知道我们开始的代码为什么引 slf4j 包。在阿里的开发手册上一条 强制:应用中不可直接使用日志系统(log4j、logback)中的

简单搭建一个SSM项目(一)

假装没事ソ 提交于 2020-01-20 03:06:04
简单搭建一个用户管理的 SSM 项目框架,虽然也能用 servlet+jdbc 搭建更简单的,不过个人感觉工作中更多用的 ssm 框架项目,这里就简单用 ssm 来搭建需要的项目吧。 准备工具: eclipse 、 jdk1.7 、 Mysql 、 maven 、 tomcat 。(请先确定计算机本身已安装好前面几个工具, myeclipse 自动集成 maven , eclipse 需要自己先配置,具体配置请自行百度) 这里先把项目的目录结构显示下 好的,现在开始 File->new->other->maven project Next-> 下面注意选择带 webapp 的原型 Next-> 这里的 group id 是你的项目在 maven 仓库中存放的路径, Artifact Id 是你的项目名称。 好了到这里为止你会发现你的 eclipse 里会出现一个 DemoSSM 的项目。 接下来我们开始一步步配置项目的依赖 jar 包。 打开项目 pom.xml 文件。 很简陋对吧,这里只是自带了一个早期版本的 junit, 具体需要更新 pom.xml 具体我就不说了下面贴出 pom.xml 配置文件。 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001

Grails logging - Is there any existing solution to be able to log the File + Line where the call actually occured?

元气小坏坏 提交于 2020-01-20 02:25:08
问题 I'm new to Grails and I'm trying to configure Log4j so it logs the exact file and line where the log call occured. No pattern works as the conversionPattern ! It seems Grails wraps the logger in a way that Log4j doesn't see the real source of the call. I'm aware of this thread, but I'm not sure how to create a custom appender. I just can't believe nobody already developed something to fix this issue! I'm open to any suggestions : Does using something else than Log4j work in Grails to get the

SSM框架笔记01:MyBatis初探

女生的网名这么多〃 提交于 2020-01-19 17:41:22
一、什么是MyBatis (一)MyBatis概述 MyBatis是支持普通SQL查询,存储过程和高级映射的优秀持久层框架。MyBatis消除了几乎所有的JDBC代码和参数的手工设置以及结果集的检索。MyBatis使用简单的XML或注解用于配置和原始映射,将接口和Java的POJOs(Plan Old Java Objects,普通的Java对象)映射成数据库中的记录。 (二)ORM工具的基本思想 无论是Hibernate还是MyBatis,你会发现它们的共同点: 从配置文件(通常是XML配置文件)得到 sessionFactory。 由sessionFactory对象产生session。 在session 中完成对数据的增删改查和事务提交等。 在用完之后关闭session。 在Java对象和数据库之间有做mapping的配置文件,也通常是xml 文件。 二、创建数据库与表 1、创建MySQL数据库mybatis 2、 建表user CREATE TABLE ` user ` ( ` id ` int ( 11 ) NOT NULL AUTO_INCREMENT , ` name ` varchar ( 50 ) DEFAULT NULL , ` age ` int ( 11 ) DEFAULT NULL , ` address ` varchar ( 255 ) DEFAULT

Mybatis学习03

大憨熊 提交于 2020-01-19 15:04:49
title: Mybatis学习03 date: 2020-01-19 13:03:20 tags: Mybatis学习的第二天,内容有日志和分页。 <!--more--> 1、日志 1、日志的设置 在mybatis核心配置文件中设置,在 <settings> </settings> 标签中使用 <setting> </setting> 来配置。 Mybatis内置了多个日志,有: SLF4J LOG4J (常用) LOG4J2 JDK_LOGGING COMMONS_LOGGING STDOUT_LOGGING (常用,标准日志) NO_LOGGING 例如STDOUT_LOGGING的配置则需在配置文件中加入: <!-- mybatis的设置--> <settings> <setting name="logImpl" value="STDOUT_LOGGING"/> </settings> 效果如下: 2、LOG4J log4j的解释: Log4j是Apache的一个开源项目,通过使用Log4j,我们可以控制日志信息输送的目的地是控制台、文件、GUI组件,甚至是套接口服务器、NT的事件记录器、UNIX Syslog守护进程等 。 我们也可以控制每一条日志的输出格式 。 可以通过一个配置文件来灵活地进行配置 开始使用: Maven添加依赖 <!-- https:/

Spring Boott基础教程五:日志配置-logback和log4j2

我是研究僧i 提交于 2020-01-19 02:45:15
目录 1、默认配置文件配置(不建议使用:不够灵活,对log4j2等不够友好) 2、引用外部配置文件 2.1、logback配置方式: 2.2、log4j配置 3、比较 支持日志框架:Java Util Logging, Log4J2 and Logback,默认是使用logback 配置方式:默认配置文件配置和引用外部配置文件配置 1、默认配置文件配置(不建议使用:不够灵活,对log4j2等不够友好) # 日志文件名,比如:roncoo.log,或者是 /var/log/roncoo.log logging.file=roncoo.log # 日志级别配置,比如: logging.level.org.springframework=DEBUG logging.level.*=info logging.level.org.springframework=DEBUG 2、引用外部配置文件 2.1、logback配置方式: spring boot默认会加载classpath:logback-spring.xml或者classpath:logback-spring.groovy 使用自定义配置文件,配置方式为: logging.config=classpath:logback-roncoo.xml 注意:不要使用logback这个来命名,否则spring boot将不能完全实例化

Creating multiple log files of different content with log4j

Deadly 提交于 2020-01-18 03:09:19
问题 Is there a way to configure log4j so that it outputs different levels of logging to different appenders? I'm trying to set up multiple log files. The main log file would catch all INFO and above messages for all classes. (In development, it would catch all DEBUG and above messages, and TRACE for specific classes.) Then, I would like to have a separate log file. That log file would catch all DEBUG messages for a specific subset of classes, and ignore all messages for any other class. Is there

Creating multiple log files of different content with log4j

二次信任 提交于 2020-01-18 03:06:34
问题 Is there a way to configure log4j so that it outputs different levels of logging to different appenders? I'm trying to set up multiple log files. The main log file would catch all INFO and above messages for all classes. (In development, it would catch all DEBUG and above messages, and TRACE for specific classes.) Then, I would like to have a separate log file. That log file would catch all DEBUG messages for a specific subset of classes, and ignore all messages for any other class. Is there

Log separate log levels to separate files in log4j2 properties file

感情迁移 提交于 2020-01-17 08:31:50
问题 Is there any way We can create separate log files for different log levels. All I want is to log "error" logs to one file and "info" logs to another file. I did not find any solution to do this in log4j2.properties. Here is the log4j2.xml which I got and it works fine. Can anyone help me writing the same in properties file. <?xml version="1.0" encoding="UTF-8"?> <Configuration status="WARN"> <Properties> <Property name="log-path">logs</Property> </Properties> <Appenders> <Console name=

Log separate log levels to separate files in log4j2 properties file

喜夏-厌秋 提交于 2020-01-17 08:31:07
问题 Is there any way We can create separate log files for different log levels. All I want is to log "error" logs to one file and "info" logs to another file. I did not find any solution to do this in log4j2.properties. Here is the log4j2.xml which I got and it works fine. Can anyone help me writing the same in properties file. <?xml version="1.0" encoding="UTF-8"?> <Configuration status="WARN"> <Properties> <Property name="log-path">logs</Property> </Properties> <Appenders> <Console name=