Has someone experience with log4j and knows what “the constructor () is not visible means” ?
Here’s the code for the Main-class:
import org.apache.log4j.xml.DOMConfigurator;
import stdGame.*;
public class Main {
public static void main(String[] args) {
DOMConfigurator.configureAndWatch( "data/log/myLoggerConfig.xml", 60*1000 );
new LogTest();
}
}
The LogTest-class is located in stdGame-package, which is already imported as you can see.
The code is working as desired, when placing the LogTest-class in the same package as the Main-class.
Here is the code for the LogTest()-class:
package stdGame;
import org.apache.log4j.Logger;
public class LogTest {
private static Logger logger = Logger.getLogger(LogTest.class);
LogTest() {
logger.info("My info-msg in LogTest.");
logger.error("My error-msg in LogTest.");
}
}
Try placing them into the same package, the error message will disapear. But i need them placed into seperated packages.
Finally this is the myLoggerConfig.xml-file:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="MeinAppender" class="org.apache.log4j.DailyRollingFileAppender">
<param name="datePattern" value="'.'yyyy-MM-dd_HH-mm" />
<param name="file" value="data/log/myLogfile.log" />
<param name="Append" value="true" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{ISO8601} %-5p [%t] %c: %m%n" />
</layout>
</appender>
<root>
<priority value="INFO" />
<appender-ref ref="MeinAppender" />
</root>
</log4j:configuration>
Your class
LogTestis instdNamepackage and it’s constructor haspackage-privateaccess. It seemsMainclass is in some package other thanstdNameand so the compiler is complaining thatLogTest()constructor is not visible inMain‘s package. Change the constructor ofLogTestto public.