log4j

[日志]Java日志性能那些事

人盡茶涼 提交于 2019-12-04 17:48:11
在任何系统中,日志都是非常重要的组成部分,它是反映系统运行情况的重要依据,也是排查问题时的必要线索。绝大多数人都认可日志的重要性,但是又有多少人仔细想过该怎么打日志,日志对性能的影响究竟有多大呢?今天就让我们来聊聊Java日志性能那些事。 说到Java日志,大家肯定都会说要选择合理的日志级别、合理控制日志内容,但是这仅是万里长征第一步……哪怕一些 DEBUG 级别的日志在生产环境中不会输出到文件中,也可能带来不小的开销。我们撇开判断和方法调用的开销,在 Log4J 2.x的性能文档 中有这样一组对比: logger.debug("Entry number: " + i + " is " + String.valueOf(entry[i])); logger.debug("Entry number: {} is {}", i, entry[i]); 上面两条语句在日志输出上的效果是一样的,但是在关闭 DEBUG 日志时,它们的开销就不一样了,主要的影响在于字符串转换和字符串拼接上,无论是否生效,前者都会将变量转换为字符串并进行拼接,而后者则只会在需要时执行这些操作。Log4J官方的测试结论是两者在性能上能相差两个数量级。试想一下,如果某个对象的 toString() 方法里用了 ToStringBuilder 来反射输出几十个属性时,这时能省下多少资源。 因此,某些仍在使用Log4J

Maven dependency log4j error

混江龙づ霸主 提交于 2019-12-04 17:36:24
问题 Hello everyone I have error which breaks up my build for no reason, here is the error message : error: error reading /.m2/repository/com/sun/jdmk/jmxtools/1.2.1/jmxtools-1.2.1.jar; error in opening zip file error: error reading /.m2/repository/com/sun/jmx/jmxri/1.2.1/jmxri-1.2.1.jar; error in opening zip file I'm using this dependency : <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.15</version> <scope>provided</scope> </dependency> How can I fix this ? 回答1:

The import org.apache.log4j cannot be resolved

↘锁芯ラ 提交于 2019-12-04 17:01:18
Eclipse, Selenium, Windows The import org.apache.log4j cannot be resolved I have followed all the documented steps I can find, i.e.: 1) the following two jar files are in the project build-path: log4j-core-2.6.2.jar and log4j-api-2.6.2.jar 2) the above two jar files are located in the following folder: C:\eclipse\apache-log4j-2.6.2-bin 3) The above folder is in my system CLASSPATH environment variable C:\eclipse\apache-log4j-2.6.2-bin 4) The project contains the following log4j.properties file in the project root # This sets the global logging level and specifies the appenders log4j.rootLogger

How to disable log4j in 3rd party jar?

拥有回忆 提交于 2019-12-04 16:33:35
问题 I'm experimenting writing a java SE swing application using JBoss weld. Weld configures logging with log4j using the following log4j.xml file in the jar: <?xml version="1.0" encoding="UTF-8"?><!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"> <!-- JBoss, Home of Professional Open Source Copyright 2009, Red Hat, Inc. and/or its affiliates, and individual contributors by the @authors tag. See the copyright.txt in the distribution for a full listing of individual contributors. Licensed under the

Kafka Log4j appender not sending messages

牧云@^-^@ 提交于 2019-12-04 16:27:45
i am quite new ot apache Kafka and log4j. i am trying to send my log messages into Kafka. Here is my log4j properties file log4j.rootLogger=INFO, stdout log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L %% %m%n log4j.appender.KAFKA=kafka.producer.KafkaLog4jAppender log4j.appender.KAFKA.BrokerList=localhost:9092 log4j.appender.KAFKA.Topic=kfkLogs log4j.appender.KAFKA.SerializerClass=kafka.producer.DefaultStringEncoder log4j.appender.KAFKA.layout

日志服务的总结

只愿长相守 提交于 2019-12-04 16:19:37
一、日志(Log) 日志(Log) 是系统在运行过程中变化的一种抽象,其内容为指定对象的某些操作和其操作结果按时间的有序集合。文件日志(LogFile)、事件(Event)、数据库日志(BinLog)、度量(Metric)数据都是日志的不同载体。在文件日志中,每个日志文件由一条或多条日志组成,每条日志描述了一次单独的系统事件,是日志服务中处理的最小数据单元。 二、日志服务 Log Service是针对日志类数据的一站式服务。 1.实时采集与消费(LogHub) 用途:数据清洗(ETL)、流计算(Stream Compute)、监控与报警、 机器学习与迭代计算。 2.查询与实时分析(Search/Analytics) 用途:DevOps/线上运维,日志实时数据分析,安全诊断与分析,运营与客服系统 3.投递数仓(LogShipper) 用途:数据仓库 + 数据分析、审计、推荐系统与用户画像。 三、概念 日志库(Logstore) 是日志服务中日志数据的收集、存储和查询单元。每个日志库隶属于一个项目,且每个项目可以创建多个日志库。 分区(Shard每个日志库分若干个 分区(Shard) ,每个分区由MD5左闭右开区间组成,每个区间范围不会相互覆盖,并且所有的区间的范围是MD5整个取值范围。 文件日志(LogFile)、事件(Event)、数据库日志(BinLog)、度量(Metric

Log4j2 auto rollover after specified duration

空扰寡人 提交于 2019-12-04 16:12:18
I am using RollingFile appender. I want the log file to be rolled after every 20 minutes irrespective of the logging event. For instance in an hour I should have 3 log files even though there might have not been any logging in that hour. Is this possible using Log4j2? If yes please provide the configuration ( in log4j2.xml) that are required. The below config does not seem to work : <RollingFile name="RECHARGE_NMCD" fileName="D:/rc_nmcd/rc_nmcd.log" append="true" bufferedIO="false" filePattern="D:/rc_nmcd/rc_nmcd_%d{yyyy-MM-dd-HH-mm}.process"> <PatternLayout> <Pattern>%m%n</Pattern> <

Using different Log files for every thread created

不打扰是莪最后的温柔 提交于 2019-12-04 16:08:39
I am working on logging with log4j, i have sample code which creats certain number of threads , i want to use different log files for each threads. so I have use the PropertyConfigurator.configure() which takes a property object. I have configured the property object in my code i.e hardcoded , but I want to load it external to code. Now I want to provide all the configurations externally through a property file i.e not to hardcode them in code and at runtime add the two properties - props.setProperty("log4j.logger."+"Thread" + Thread.currentThread().getName(),"DEBUG, file"); and props

Log4J attach only one class to an appender

僤鯓⒐⒋嵵緔 提交于 2019-12-04 16:02:01
I need to poll the JVM memory stats of my running application on a regular basis. I'm running a service that does this and writes the stats to the root Logger (I don't have much control over Root Logger usage or not). What I want to do is route just these logging messages to a single appender. This appender should only process logging messages from this one class, and not from any other class. The other appenders shouldn't receive the messages from this one class. So far I have the log messages only going to this 'memoryStats' appender. However, all the other logging message are also going to

Please initialize the log4j system properly warning

喜欢而已 提交于 2019-12-04 15:38:50
问题 Here is the error message - log4j:WARN No appenders could be found for logger (SerialPortUtil). log4j:WARN Please initialize the log4j system properly. log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info. Here is the invocation in the SerialPortUtil class - private static final Logger log = Logger.getLogger(SerialPortUtil.class.getSimpleName()); . . . log.info("Serial port " + port.getName() + " is available"); Here is the content of my log4j.properties file -