Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log file stopped rotating daily since I updated to 2.19.0 #1269

Closed
SK-Yang opened this issue Feb 7, 2023 · 9 comments
Closed

Log file stopped rotating daily since I updated to 2.19.0 #1269

SK-Yang opened this issue Feb 7, 2023 · 9 comments
Labels
bug Incorrect, unexpected, or unintended behavior of existing code configuration Affects the configuration system in a general way unconfirmed Issue can not be reproduced

Comments

@SK-Yang
Copy link

SK-Yang commented Feb 7, 2023

I was using 2,17.0 with log4j-1.2-api 2.17.0 to read my external log4j.properties file and everything went well. But since those deserialization issues appeared last year, I have updated them to 2.19.0, then I noticed my log file stopped rotating daily and keep everything in one since the update. I tried to restart the jvm and nothing change, so I think it might be the log4j's issue.

Configuration

Version: 2.19.0

Operating system: Win server 2019

JDK: openjdk version "1.8.0_171-1-redhat"

@ppkarwasz
Copy link
Contributor

@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).

@SK-Yang
Copy link
Author

SK-Yang commented Feb 7, 2023

@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

@SK-Yang
Copy link
Author

SK-Yang commented Feb 12, 2023

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

@ppkarwasz
Copy link
Contributor

@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).

@SK-Yang
Copy link
Author

SK-Yang commented Feb 13, 2023

@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

@ppkarwasz
Copy link
Contributor

@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.

@SK-Yang
Copy link
Author

SK-Yang commented Feb 13, 2023

@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.

@ppkarwasz
Copy link
Contributor

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

@jvz jvz added bug Incorrect, unexpected, or unintended behavior of existing code configuration Affects the configuration system in a general way labels Oct 15, 2023
@ppkarwasz ppkarwasz added the unconfirmed Issue can not be reproduced label Oct 26, 2023
@ppkarwasz
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Incorrect, unexpected, or unintended behavior of existing code configuration Affects the configuration system in a general way unconfirmed Issue can not be reproduced
Projects
None yet
Development

No branches or pull requests

3 participants