• Hibernate4.3.5搭建Log4j日志环境


    本文记录Hibernate4.3.5搭建Log4j日志环境的过程

    1、搞清楚Hibernate4.3.5的日志环境依赖

    方法:查看帮助文档

    3.5. Logging
    
    Important
    Completely out of date. Hibernate uses JBoss Logging starting in 4.0. This will get documented as we migrate this content to the Developer Guide.
    Hibernate utilizes Simple Logging Facade for Java (SLF4J) in order to log various system events. SLF4J can direct your logging output to several logging frameworks (NOP, Simple, log4j version 1.2, JDK 1.4 logging, JCL or logback) depending on your chosen binding. In order to setup logging you will need slf4j-api.jar in your classpath together with the jar file for your preferred binding - slf4j-log4j12.jar in the case of Log4J. See the SLF4J documentation for more detail. To use Log4j you will also need to place a log4j.properties file in your classpath. An example properties file is distributed with Hibernate in the src/ directory.

    第1段说hibernate4.0之后用JBoss Logging。具体怎么个用法还没研究过,第2段说Hibernate为了在不同的系统中记录日志利用了SLF4J,SLF4J是一套日志的接口,它可以匹配多种日志框架。为了 使用Log4j需要这两个jar包:slf4j-api.jar、slf4j-log4j12.jar。前者是slf4j的api包,后者是slf4j到log4j的适配器包。

    看到这问题就来了,这两个jar包去哪里找呢?

    方法:查看一下Hibernate4.3.5的lib目录里有没有,发现hibernate-release-4.3.5.Finalliboptionalehcache目录里有slf4j-api-1.6.1.jar,有了slf4j的api包,slf4j到log4j的适配器包去哪里找呢,去把slf4j官网把1.6.1下载下来看一下发现适配器官方发布包里面就有slf4j-1.6.1slf4j-log4j12-1.6.1.jar。

    有了这两个包就OK了吗?肯定不行啊,既然要搭建log4j日志环境,当然还需要log4j核心包,log4j的jar包版本那么多,我应该下载哪个版本呢?当然要下载适配器对应的版本了即:log4j-1.2.16,去官网下载下来。

    2、目录结构

    我们已经搞清楚了Hibernate4.3.5搭建log4j日志环境所需要的jar包,把他们添加到自己的工程里面,添加log4j的配置文件(示例文件:hibernate-release-4.3.5.Finalprojectetclog4j.properties),如此以后Hibernate4.3.5的log4j日志环境基本搞定。目录结构如下所示:

  • 相关阅读:
    JS 检查是否在微信浏览器
    php如何判断文件是否存在,包括本地和远程文件
    SQL 截取字段空格之前的数据
    JS 上拉加载
    struts2项目需要加入的jar包
    eclipse+maven+jetty环境下修改了文件需要重启才能修改成功
    根据父节点查询出所有的子节点
    oracle中,行转列函数wm_concat()结果有长度限制,重写该函数解决
    乱码!Eclipse 的控制台console必须用GBK编码。
    webpack 入门和常用插件的使用
  • 原文地址:https://www.cnblogs.com/foreverngu/p/3870476.html
Copyright © 2020-2023  润新知