log4j

java: how to set a global thread-ID?

情到浓时终转凉″ 提交于 2019-12-07 20:48:29
问题 Is there any possibility to set unique ID for a thread? In distributed system where threads are created on many different machines (e.g. by RMI)? I need it to create log messages. From my research I know that it can be done using log4j mdc/ndc, but only in single thread. My problem is that ID has to be set when thread is created (to use the same ID for threads on different JVM but for the same request) I am new to distributed systems. 回答1: If you want to have a globally unique request id, you

使用Log4J来作为Spring Boot的日志系统

柔情痞子 提交于 2019-12-07 20:35:13
1. 修改 build.gradle 排除掉对logback的依赖,添加对log4j的依赖 dependencies { compile('org.springframework.boot:spring-boot-starter-web') { exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging' } compile('org.slf4j:slf4j-api') compile('org.slf4j:slf4j-log4j12') compile('commons-logging:commons-logging') } 2.设置定log4j的配置文件位置,例如: 把 log4j-dev.xml 文件放到 src/main/resources 目录下,然后在 application.properties 文件里设置 logging.config=classpath:log4j-dev.xml 3. 在Spring Boot的启动类里用代码手动加载log4j,例如: @SpringBootApplication public class Application implements EnvironmentAware { private Environment env;

log4j升级版日志框架logback的使用以及配置详解

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-07 20:34:25
一、logback的介绍   Logback是由log4j创始人设计的另一个开源日志组件,官方网站: http://logback.qos.ch。它当前分为下面下个模块:   logback-core:其它两个模块的基础模块   logback-classic:它是log4j的一个改良版本,同时它完整实现了slf4j API使你可以很方便地更换成其它日志系统如log4j或JDK14 Logging   logback-access:访问模块与Servlet容器集成提供通过Http来访问日志的功能 二、logback取代log4j的理由:   1、更快的实现:Logback的内核重写了,在一些关键执行路径上性能提升10倍以上。而且logback不仅性能提升了,初始化内存加载也更小了。   2、非常充分的测试:Logback经过了几年,数不清小时的测试。Logback的测试完全不同级别的。   3、Logback-classic非常自然实现了SLF4j:Logback-classic实现了SLF4j。在使用SLF4j中,你都感觉不到logback-classic。而且因为logback-classic非常自然地实现了slf4j , 所 以切换到log4j或者其他,非常容易,只需要提供成另一个jar包就OK,根本不需要去动那些通过SLF4JAPI实现的代码。   4、非常充分的文档

jboss log4j冲突分析与解决

孤街醉人 提交于 2019-12-07 20:17:29
Log4j 作为日志组件被大多数的系统所使用, Jboss 也不例外的采用了 Log4j 作为它的日志输出组件。 但在使用 JBoss 时,很多人经常碰到一些冲突,这些冲如自己配置的 log4j 文件无效,系统抛 org.jboss.logging.util.OnlyOnceErrorHandlerobject is not assignable to a or g.apache.log4j.spi.ErrorHandler variable 异常等。为了解决造成这方面的原因,我们需要分析 Jboss 和 log4j 的一些关系。本文的下面内提供了一个最佳的配置及对问题的分析,在理解了下面的内容后,相信大家都能解决 log4j 的冲突问题,并找到符合自己的一种解决方法。 一、最佳无冲突配置 解决 jboss 和 log4j 冲突的最理想配置如下: 配置 jboss_server_home/deploy/jbossweb-tomcat55.sar/META-INF/jboss-service.xml 文件里的 Java2ClassLoadingCompliance 及 UseJBossWebLoader 为 false ,如果存在 WEB-INF/jboss-web.xml ,则里面的 java2ClassLoadingCompliance 及

Logging hibernate SQL using log4j

有些话、适合烂在心里 提交于 2019-12-07 20:15:28
I am using hibernate and I am trying to log all the SQL that hibernate automatically generates to the console so that i can see if there is an error in my mapping. I am using log4j so i am trying to use log4j.logger.org.hibernate.SQL=ALL, SQL_APPENDER to display all the SQL that hibernate is using but this is not working. I have added this line of code to my log4j.properties file but it is not working! am i forgetting something or doing something wrong i want to display something like this Hibernate: INSERT INTO mkyong.stock_transaction (CHANGE, CLOSE, DATE, OPEN, STOCK_ID, VOLUME) VALUES (?,

Log4j daily rolling catalina.out without restarting Tomcat?

爱⌒轻易说出口 提交于 2019-12-07 20:13:09
问题 i am having trouble with configuring Log4j correctly. I was expecting Log4j to rotate my catalina.out file at midnight when configuring it like the following.. log4j.properties: log4j.rootLogger=INFO, CATALINA # Define all the appenders log4j.appender.CATALINA=org.apache.log4j.DailyRollingFileAppender log4j.appender.CATALINA.File=/var/log/tomcat7/catalina.out log4j.appender.CATALINA.Append=true log4j.appender.CATALINA.Encoding=UTF-8 # Roll-over the log once per day log4j.appender.CATALINA

Log4J – Runtime variable substitution

隐身守侯 提交于 2019-12-07 19:44:32
问题 Log4J appears to have an annoying restriction – at runtime, variable substitution does not appear to work. In this example File: Log4j.properties file_pattern=%d{ISO8601} %-5p %m%n log4j.rootLogger=DEBUG, FileAppender log4j.appender.FileAppender=org.apache.log4j.FileAppender log4j.appender.FileAppender.layout=org.apache.log4j.PatternLayout log4j.appender.FileAppender.layout.ConversionPattern=${file_pattern} log4j.appender.FileAppender.File=log4jtest1.log log4j.appender.FileAppender.Threshold

idea+mybatis+maven main测试

北城余情 提交于 2019-12-07 19:03:23
项目结构 pom文件 <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.bdqn</groupId> <artifactId>ssmDemo</artifactId> <version>1.0-SNAPSHOT</version> <packaging>war</packaging> <name>ssmDemo Maven Webapp</name> <!-- FIXME change it to the project's website --> <url>http://www.example.com</url> <properties> <project.build.sourceEncoding>UTF-8</project.build

Logging with DEBUG level in JBoss 7.1.1

青春壹個敷衍的年華 提交于 2019-12-07 18:21:55
问题 Goal: My application should have messages with ERROR and DEBUG levels. Level of logging must set (switch) via JBoss Admin Console. Logging should be written to standard JBoss log file and server console. I tried to use java.util.logging.Logger, but this logger have not necessary levels. I switched to log4j with slf4j. Messages with ERROR level is exist. Problem with DEBUG and System.out.println. Interesting, that DEBUG level is visible in testing phase. import org.slf4j.Logger; import org

Linux CRON定时执行JAR程序时,log4j日志无法输出到指定目录的问题

拥有回忆 提交于 2019-12-07 17:26:37
Linux CRON定时执行JAR程序时,log4j日志无法输出到指定目录的问题 在linux下,使用CRON定时执行xxx.sh脚本,xxx.sh脚本中执行java -jar aaa.jar; aaa.jar中log4j的日志没有输出到默认的aaa.jar同目录下,而是输出到了系统的/root/ 目录下了; 解决方法: 在xxx.sh脚本中,java -jar aaa.jar命令之前,添加cd /usr/aaa/ ,这样aaa.jar的log4j日志就输出到aaa目录下了; 来源: CSDN 作者: arcticJian 链接: https://blog.csdn.net/arcticJian/article/details/79422476