Git Product home page Git Product logo

Comments (9)

ppkarwasz avatar ppkarwasz commented on May 21, 2024

@SK-Yang,

Can you add the contents of your log4j.properties file to your question? Since version 2.17.0, log4j-1.2-api has changed a lot. For example the builder for org.apache.log4j.RollingFileAppender configured a time-based rotation instead of a size-based one (cf. #710).

from logging-log4j2.

SK-Yang avatar SK-Yang commented on May 21, 2024

@ppkarwasz

Sure, there you go

# Encoding: UTF-8

log4j.logger.com.Common.model.Log4jAP=ALL, AP_Log

log4j.appender.AP_Log=org.apache.log4j.DailyRollingFileAppender
log4j.appender.AP_Log.File=D:/Handler_AP/log/AP/AP_Log.log
log4j.appender.AP_Log.DatePattern='.'yyyy-MM-dd
log4j.appender.AP_Log.Append=true
log4j.appender.AP_Log.encoding=UTF-8
log4j.appender.AP_Log.layout=org.apache.log4j.PatternLayout
log4j.appender.AP_Log.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss,SSS} [%-5p] %m%n

from logging-log4j2.

SK-Yang avatar SK-Yang commented on May 21, 2024

@ppkarwasz
Hi, may I ask if you see anything wrong about the DailyRollingFileAppender? or my settings?

from logging-log4j2.

ppkarwasz avatar ppkarwasz commented on May 21, 2024

@SK-Yang,

Your configuration works correctly, but the logger name "com.Common.model.Log4jAP" seems suspicious (if Common is a package name, it should be lowercase common).

from logging-log4j2.

SK-Yang avatar SK-Yang commented on May 21, 2024

@ppkarwasz

"com.Common.model.Log4jAP" seems suspicious
Yes, it's package name. Somehow the top guys made rules to name like this long time ago.

Hmmm, so my config should be working properly but it isn't... I have enabled log4j's root logger, and it printed this line in log

log4j:ERROR Failed to rename [D:/Handler_AP/log/AP/AP_Log.log] to [D:/Handler_AP/log/AP/AP_Log.log.2023-02-11]

Is this a bug like this?
https://bz.apache.org/bugzilla/show_bug.cgi?id=29726

from logging-log4j2.

ppkarwasz avatar ppkarwasz commented on May 21, 2024

@SK-Yang,

Messages prefixed by log4j: were used by the unsupported Log4j 1.2. Make sure that:

  • You don't have log4j:log4j on your classpath,
  • You have org.apache.logging:log4j-1.2-api on your classpath,
  • Either the system property log4j1.compatibility=true is set or log4j.configuration points to your log4j.properties file.

from logging-log4j2.

SK-Yang avatar SK-Yang commented on May 21, 2024

@ppkarwasz

@SK-Yang,

Messages prefixed by log4j: were used by the unsupported Log4j 1.2. Make sure that:

* You **don't** have [`log4j:log4j`](https://mvnrepository.com/artifact/log4j/log4j) on your classpath,

I have checked its lib folder, POM, and IDE build path, no old Log4j 1.2 included.

* You have [`org.apache.logging:log4j-1.2-api`](https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-1.2-api) on your classpath,

log4j-1.2-api-2.19.0.jar, log4j-api-2.19.0.jar, log4j-core-2.19.0.jar. just them.

* Either the system property `log4j1.compatibility=true` is set or `log4j.configuration` points to your `log4j.properties` file.

doesn't have any system prop setting inside my program, but I do have a simple mechanism to read my properties file.

public class Log4j {

	public final static Logger LOG = Logger.getLogger(Log4j.class);
	private static boolean configurated = false;

	public Log4j() {
	};

	public Log4j(String config_path) {
		if (configurated == false) {
			Properties p = new Properties();

			try {
				p.load(new FileInputStream(config_path));
				PropertyConfigurator.configure(p);
				configurated = true;
			} catch (IOException e) {
				System.out.println("[Error] Unable to read log4j config: " + e.getMessage());
			} finally {
				if (p != null) {
					p.clear();
				}
			}
		}
	};
}

This works fine since 1.12.x to 2.17.0 over the past few years. I still cannot understand why it won't on 2.19.0.

from logging-log4j2.

ppkarwasz avatar ppkarwasz commented on May 21, 2024

PropertyConfigurator#configure() was a no-op before version 2.17.2 (cf. source code). Another mechanism must be configuring your logging system.

from logging-log4j2.

ppkarwasz avatar ppkarwasz commented on May 21, 2024

I am closing this since it can not be reproduced and it probably concerns Log4j 1.x/Reload4j.

Feel free to reopen it if there is new data.

from logging-log4j2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.