log4j:WARN Please initialize the log4j system properly - java

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.

Related

Install Esper in Eclipse

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.

Error running a java program that uses log4j

So i am trying to run a java file launch.bat sdoc(launch is a small script that have the jar used, but if necessary i can post it here) and i get this error.
log4j:ERROR setFile(null,true) call failed.
java.io.FileNotFoundException: C:Users
ennasDesktopwebstorelogsvolume-server.sdoc.log
My config file is:
log4j.appender.dest.File=C:\Users\nennas\Desktop\webstore\logs\volume-server.sdoc.log
log4j.appender.dest.layout=org.apache.log4j.PatternLayout
log4j.appender.dest=org.apache.log4j.RollingFileAppender
log4j.rootCategory=INFO, dest
log4j.appender.dest.layout.ConversionPattern=%d - %m%n
I already try some solution like changing \ to / and running as admin, the path is the absolute path. The folder exist but the strange thing is that in the error the url appears all together, by the way i am using windows 7. Ty for the help
Change this
log4j.appender.dest.File=C:\Users\nennas\Desktop\webstore\logs\volume-server.sdoc.log
by
log4j.appender.dest.File=C://Users//nennas//Desktop//webstore//logs//volume-server.sdoc.log
You can try also this
log4j.appender.dest.File=C:\\Users\\nennas\\Desktop\\webstore\\logs\\volume-server.sdoc.log
There is a lot of time since I donĀ“t work with windows, but i remember similar problems with windows path and log4j

Embedding GATE and trying to compile and run StandAloneAnnie

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 :)

Application specific log in tomcat 7 using JULI?

I'm using java system logging in tomcat 7, but no logging statements get written to the log. I've added this file to my WEB-INF/classes. The log file "new-xyz-test" gets created (so I have at least some of the config right) but its empty - no log statements get printed to it.
handlers=java.util.logging.ConsoleHandler, org.apache.juli.FileHandler
org.apache.juli.FileHandler.level=ALL
org.apache.juli.FileHandler.directory=${catalina.base}/logs
org.apache.juli.FileHandler.prefix=new-xyz-test-
java.util.logging.ConsoleHandler.level=ALL
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
com.xyz.level=ALL
com.xyz.handlers=org.apache.juli.FileHandler
To configure JULI in the web applications you need have a logging.properties file in the WEB-INF/classes directory. If you use the default handlers, you may lose messages. You need to specify a prefix for the handler in your file.
handlers=1FILE.org.apache.juli.FileHandler, java.util.logging.ConsoleHandler
.handlers=java.util.logging.ConsoleHandler
1FILE.org.apache.juli.FileHandler.level=FINEST
1FILE.org.apache.juli.FileHandler.directory=/app-logs
1FILE.org.apache.juli.FileHandler.prefix=file-1
java.util.logging.ConsoleHandler.level=FINE
java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter
com.xyz.level=INFO
com.xyz.handlers=1FILE.org.apache.juli.FileHandler
com.abc.level=INFO
com.abc.handlers=java.util.logging.ConsoleHandler
A
handler prefix (e.g. 1FILE.) starts with a number, then has an arbitrary string, and ends with a period (.).
See more in Logging in Tomcat
Arguments in the JVM
If you are not running the Tomcat from the startup.sh or startup.bat, you need to specify:
The location of the general logging.properties for Tomcat (in the conf directory of Tomcat)
The manager org.apache.juli.ClassLoaderLogManager. This is important because allows you to configure
for each web application different loggin options. By default, a JVM process can only have a single configuration file.) ,
Similar to the next (I'm using eclipse):
-Djava.util.logging.config.file="C:\Users\Paul\workspaces\utils\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\conf\logging.properties" -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
By default, java.util.logging read the file that is included in the JDK or JRE, e.g.:
"C:\Software\jdk1.7.0_17\jre\lib\logging.properties"
Setting Tomcat Heap Size (JVM Heap) in Eclipse, for how to add arguments in the VM
are you sure that you write to the correct logger , i.e. Logger.getLogger("com.xyz")?
I think that you may got wrong when you wrote in logging.properties:com.xyz.level=ALL com.xyz.handlers=org.apache.juli.FileHandler in the case that you actually write to the logger Logger.getLogger(com.xyz.YourClass.class), that because in the logging properties file you should write the logger name which is in your case com.xyz.YourClass

Java Logging - where is my log file?

I'm having trouble finding my log files.
I'm using Java Logging - java.util.logging - in Eclipse 3.7.1 on Windows XP. The relevant lines of my logging.properties file are:
handlers= java.util.logging.FileHandler, java.util.logging.ConsoleHandler
.level=INFO
java.util.logging.FileHandler.pattern = %h/java%u.log
java.util.logging.FileHandler.limit = 50000
java.util.logging.FileHandler.count = 1
java.util.logging.FileHandler.formatter = java.util.logging.XMLFormatter
As far as I can figure out, after I execute these two lines:
Logger logger = Logger.getLogger("test");
logger.logp(Level.INFO, "myClass", "myMethod", "Alcatraz");
my log file should be in C:\Documents and Settings\[My Windows ID]\javaX.log where X is an integer.
I have 5 different java.log files in that directory, java0.log through java4.log, but none of them contain my log record or even a record with today's date on it. I did some googling and found Tracing and Logging which implies that my logs should be at a different location, c:\Documents and Settings\[My Windows ID]\Application Data\Sun\Java\Deployment\log. There is one file there, named plugin5581819941091650582.log, but it is essentially empty:
<?xml version="1.0" encoding="windows-1252" standalone="no"?>
<!DOCTYPE log SYSTEM "logger.dtd">
<log>
</log>
Its creation date is last week. (I'm not sure what process created it; I certainly didn't create it explicitly.)
So where is my log file then? I can't think of anywhere else to look.
Also, does anyone know when changes to logging.properties take effect? If I changed the log level or the FileHandler.pattern, what would have to happen before my program saw the changes? Simply saving the changes in logging.properties is clearly not enough. Will I need to restart Eclipse? Or reboot the computer? Just curious. That's not nearly as big a deal to me as finding out where my log file actually is.
Where is your logging.properties file located? It should be available in the root of the classpath. As a sanity check, what does the following code print?
System.out.println(getClass().getClassLoader().getResource("logging.properties"));
If the code is in a static context, use
System.out.println(ClassName.class.getClassLoader().getResource("logging.properties"));
Location of log file can be control through logging.properties file. And it can be passed as JVM parameter ex : java -Djava.util.logging.config.file=/scratch/user/config/logging.properties
Details:
https://docs.oracle.com/cd/E23549_01/doc.1111/e14568/handler.htm
Configuring the File handler
To send logs to a file, add FileHandler to the handlers property in the logging.properties file. This will enable file logging globally.
handlers= java.util.logging.FileHandler
Configure the handler by setting the following properties:
java.util.logging.FileHandler.pattern=<home directory>/logs/oaam.log
java.util.logging.FileHandler.limit=50000
java.util.logging.FileHandler.count=1
java.util.logging.FileHandler.formatter=java.util.logging.SimpleFormatter
java.util.logging.FileHandler.pattern specifies the location and pattern of the output file. The default setting is your home directory.
java.util.logging.FileHandler.limit specifies, in bytes, the maximum amount that the logger writes to any one file.
java.util.logging.FileHandler.count specifies how many output files to cycle through.
java.util.logging.FileHandler.formatter specifies the java.util.logging formatter class that the file handler class uses to format the log messages. SimpleFormatter writes brief "human-readable" summaries of log records.
To instruct java to use this configuration file instead of $JDK_HOME/jre/lib/logging.properties:
java -Djava.util.logging.config.file=/scratch/user/config/logging.properties
The .log file is in your \workspace\.metadata folder. I'm using Eclipse 4.2.
The root cause of the problem the questioner is having is that his logging.properties file is not being read.
The file specified in java.util.logging.config.file is not read from the classpath. Instead it is read from the file system relative the current directory.
For example, running the following command java -Djava.util.logging.config.file=smclient-logging.properties SMMain will read the smclient-logging.properties from the current directory. Once the correct java.util.logging.config.file is read, the logs are generated as specified in the file.
It seems that the default location has changed. To find your logfile open the Java Console with your application. in there press "s". This prints out the System- and Deployment-Properties where you can find something like:
deployment.user.logdir = C:\Users\username\AppData\LocalLow\Sun\Java\Deployment\log
There you will find your logfiles.
If its null, then the file path would be your eclipse home directory. Your logging.properties file is not raken by the system, so point the properties file to the complete path as shown below then your log file will be generated in the place of directlyr where yor prefers it. -Djava.util.logging.config.file=D:\keplereclipse\keplerws\NFCInvoicingProject\WebContent\WEB-INF\logging.properties
Debug the your variable or logger.getHandlers(): just for the instances of FileHandler, and look for its private field: files
Make sure that your logger level including your log.
Make sure that your handler level including your log.
It will be sent to your home directory. If there's no that directory in your operate system, such as windows 95/98/ME, the file should be saved to the default path like C:\Windows\.
Reflect, the same as tip 1
Field[] handlerFiles = handler.getClass().getDeclaredFields();
AccessibleObject.setAccessible(handlerFiles, true);
for (Field field : handlerFiles) {
if (field.getName().equals("files")) {
File[] files = (File[]) field.get(handler);
System.out.println(Arrays.toString(files));
}
}
The log manager will be initialized during JVM startup and completed before the main method. You can also re-initialize it in main method with System.setProperty("java.util.logging.config.file", file), which will call LogManager.readConfiguration().

Categories