I am building Java Desktop and Java Applet from the same code. Log4j is in use so almost every class in desktop version (which is original) has line like
private static final Logger LOG = LoggerFactory.getLogger(EachClassName.class);
Because Applet is not supposed to perform any io operations I had to exclude this configuration code:
InputStream is = Log4jConfigurator.class.getClassLoader().getResourceAsStream(path);
properties.load(is);
is.close();
PropertyConfigurator.configure(properties);
But now I get warnings because getLogger is still in place
log4j:WARN No appenders could be found for logger (org.game.client.Client).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
What would be the most elegant solution to avoid this warnings and use logger only in desktop version?
In your "Applet App" try to configure log4j programmatically:
turn off logging
LogManager.getRootLogger().setLevel(Level.OFF);
Add NullAppender (if setting Level.OFF is not enough)
LogManager.getRootLogger().addAppender(new NullAppender())
Related
I'm struggling to install Esper in Eclipse. I'm not good at technical issues, so please I need all details to do so.
In fact, I added all jar files of esper-5.4.0.zip in Java build path of my project. I have got the following error messages:
log4j:WARN No appenders could be found for logger (com.espertech.esper.util.ObjectInputStreamWithTCCL).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Exception in thread "main" com.espertech.esper.client.EPStatementException: Failed to resolve event type: Event type or class named 'Deposit' was not found [every A=Deposit]
at com.espertech.esper.core.service.StatementLifecycleSvcImpl.compile(StatementLifecycleSvcImpl.java:1162)
at com.espertech.esper.core.service.StatementLifecycleSvcImpl.createStopped(StatementLifecycleSvcImpl.java:298)
at com.espertech.esper.core.service.StatementLifecycleSvcImpl.createStoppedAssignName(StatementLifecycleSvcImpl.java:202)
at com.espertech.esper.core.service.StatementLifecycleSvcImpl.createAndStart(StatementLifecycleSvcImpl.java:156)
at com.espertech.esper.core.service.EPAdministratorImpl.createPatternStmt(EPAdministratorImpl.java:108)
at com.espertech.esper.core.service.EPAdministratorImpl.createPattern(EPAdministratorImpl.java:58)
at test.CEP_start.main(CEP_start.java:39)
When you create a statement like select * from Deposit that requires that you tell the engine what a "Deposit" is. That is done by adding an event type.
The documentation and tutorials have plenty of introductory examples or you could review the examples that comes with the Esper download.
I've been trying to learn GATE specifically ANNIE and TwitIE. I've seen a stand alone ANNIE java code found in the GATE website (https://gate.ac.uk/wiki/code-repository/src/sheffield/examples/StandAloneAnnie.java). I am trying to run the java file but I always get this error message (because I really don't understand how to embed GATE, please tell me how to step by step):
log4j:WARN No appenders could be found for logger (gate.Gate).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Exception in thread "main" gate.util.GateRuntimeException: Could not infer installed plug-ins home!
Please set it manually using the -Dgate.plugins.home option in your start-up script.
at gate.Gate.initLocalPaths(Gate.java:303)
at gate.Gate.init(Gate.java:163)
at StandAloneAnnie.main(StandAloneAnnie.java:81)
Java Result: 1
The problem comes from the statement:
Gate.init();
Please help, I badly need it. and thank you :)
I temporarily solved the problem by including in the code before the initialization of GATE:
Gate.init()
these set of codes:
Properties props2 = System.getProperties();
props2.setProperty("gate.plugins.home", "C:\\Program Files\\GATE_Developer_8.0\\plugins");
Properties props3 = System.getProperties();
props3.setProperty("gate.site.config", "C:\\Program Files\\GATE_Developer_8.0\\gate.xml");
I hope this will also help others :)
I got error:
log4j:WARN No appenders could be found for logger (java.lang.Class).
log4j:WARN Please initialize the log4j system properly.
I have been through many threads and forums to fix the above error, but could not find the solution to my problem.
Problem: My requirement specifies us to use the below filenames for each environment.
log.dev
log.local
log.test
How to configure my application to detect these log files?
log4j must be properly configured for logging to files.
try this :
Logger logger = Logger.getLogger(yourclassname.class);
BasicConfigurator.configure(); // basic log4j configuration
Logger.getRootLogger().setLevel(Level.INFO);
FileAppender fileAppender = null;
try {
fileAppender =
new RollingFileAppender(new PatternLayout("%d{dd-MM-yyyy HH:mm:ss} %C %L %-5p:%m%n"),"file.log");
logger.addAppender(fileAppender);
} catch (IOException e) {
e.printStackTrace();
}
logger.info("TEST LOG ENTRY");
This should create a log file named file.log in the local folder.
Use your java program and logic to removeAppender and addAppender as necessary to switch files.
Or you can create multiple logger instances each with one fileAppender if switching is required dynamically throughout the program.
This way of using log4j avoids the need for external configuration file log4j.properties.
I'm a newbie to log4j. This is what I have . I have about 20 files in different packages in a STAND ALONE JAVA APPLICATION.
I am trying to use and write log files.
Following is my log4j.properties file which is in my class path:
log4j.appender.R = org.apache.log4j.DailyRollingFileAppender
log4j.appender.R.File = /ParentFolder/ChildFolder/application.log
log4j.appender.R.Append = true
log4j.appender.R.DatePattern = '.'yyy-MM-dd
log4j.appender.R.layout = org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern = %d{yyyy-MM-dd HH:mm:ss} %c{1} [%p] %m%n
Following is the code to initialize logging in my main method
final String LOG_FILE = "C:/eclipse_workspace/lib/log4j.properties";
Properties logProp = new Properties();
try
{
logProp.load(new FileInputStream (LOG_FILE));
PropertyConfigurator.configure(logProperties);
logger.info("Logging enabled");
}
catch(IOException e)
{
System.out.println("Logging not enabled");
}
In every java class of the application I have the following code
import org.apache.log4j.*;
private static final Logger logger = Logger.getLogger(TheActualClassName.class);
But I get the following warning messages when I run the app.
log4j:WARN No appenders could be found for logger (com.xxx.myApp.MainProgram.MyFileName).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
What am I doing wrong?? The log file "application.log" is not being generated
May need the following line:
# Set root logger level to INFO and appender to R.
log4j.rootLogger=INFO, R
The root logger is always available and does not have a name.
Since the version 1.2.7, log4j (with the LogManager class) looks for log4j.xml in the classpath first. If the log4j.xml not exists, then log4j (with the LogManager class) looks for log4j.properties in the classpath.
Default Initialization Procedure
LogManager xref
If you are going to use a file named log4j.properties, and it's on your application's classpath, there is no need to even call PropertyConfiguration or DOMConfigurator - log4j will do this automatically when it is first initialized (when you first load a logger).
The error message seems to indicate that your configuration is not being loaded.
Add the VM argument -Dlog4j.debug to your application to have log4j spit out a whole bunch of information when it starts up, which includes which files it tries to load and what values it finds in the configuration.
Raghu ,if you are using stand alone configuration for configuring log4j Properties then use can use BasicConfigurator.configure() method for solving your appenders issue.
How to resolve these following errors... Am I missing some jar file???
log4j:WARN No appenders could be found for logger (smslib).
log4j:WARN Please initialize the log4j system properly.
org.smslib.GatewayException: Comm library exception: java.lang.RuntimeException: javax.comm.PortInUseException: Port currently owned by Unknown Windows Application
at org.smslib.modem.SerialModemDriver.connectPort(SerialModemDriver.java:97)
at org.smslib.modem.AModemDriver.connect(AModemDriver.java:110)
at org.smslib.modem.ModemGateway.startGateway(ModemGateway.java:158)
at org.smslib.Service$1Starter.run(Service.java:252)
WaitCommEvent: Error 31
WaitCommEvent: Error 31
My first thought was that your log4j XML or properties file wasn't picked up when log4j initialized. Make sure one of them is in your CLASSPATH.
A more careful reading of your exception suggests that you're trying to use a port that a Windows app already has taken control of.
Do a "netstat -a" to see what ports are currently in use and what's attached to them. Pick another one for your log4j appender to use.
Have you written a custom appender to write log messages to SMS? Something else is using the port you've chosen.
EDIT:
The jre/lib directory is not in the CLASSPATH. You should not be putting any of your code in that directory. It should end up in the directory where your compiled .class files are written to.