I have some Java code that uses log4j logging. As a standalone application it works fine and log statements are generated as expected. Now, I am invoking this Java code through JPype service calls. The jar files are being added to the JVM as follows. Surprisingly, the Java code still works fine and I can see the output but no log files are created.
def start_jvm():
javapath = JavaAlgorithmAttributes.java_resolver_path
cp = "-Djava.class.path=%s" % (
+ f"{javapath}/vendor/log4j-core-2.17.1.jar;"
+ f"{javapath}/vendor/log4j-api-2.17.1.jar;"
+ f"{javapath}/vendor/log4j-slf4j-impl-2.17.1.jar;"
+ f"{javapath}/vendor/slf4j-api.jar;"
+ f"{javapath}/properties/log4j2.xml"
)
startJVM(getDefaultJVMPath(), "-ea", cp)
Could someone please provide some insights?
Thanks in advance!
Okay, got it. Turns out, the log4j2.xml files needs to be passed to the jvm as an argument, not the way I was doing above. It should be added as follows:
-Dlog4j.configurationFile=log4j2.xml
Regards
Related
I want to write logging-messages to a defined file into the tomcat's log-folder, using eclipse, maven, tinylog.
Problem: There is no webapp.log as soon as I run the app in tomcat.
In eclipse everything works fine.
What I did:
add Maven-dependency tinylog-1.2.jar
set configuration-parameter in Run Configuration (Main-Tab) so the tinylog-properties can be found for the build-process:
name: -Dtinylog.configuration
value: C:\Program
Files\Tomcat\apache-tomcat-9.0.0.M13\webapps\folder\subfolder\tinylog.properties
in Java-Class:
import org.pmw.tinylog.Logger;
...
Logger.info(message);
tinylog.properties looks like:
tinylog.writer = file
tinylog.writer.filename = webapp.log
tinylog.writer.buffered = true
tinylog.writer.append = true
tinylog.level = info
I also tried different file-references but none of them worked:
tinylog.writer.file = C:\Program Files\Tomcat\apache-tomcat-9.0.0.M13\logs\webapp.log
tinylog.writer.file= "C:\Program Files\Tomcat\apache-tomcat-9.0.0.M13\logs\webapp.log"
Does anybody know how to write the logs into the named path-file?
Thanks for any valuable hint.
I propose to use the tinylog-jul artifact instead of the usual tinylog artifact. tinylog-jul provides the tinylog API, but uses the Tomcat logging back end. So, you don't need to configure tinylog. All log entries will be automatically output as you are used to with other logging APIs on Tomcat.
I am trying to run a spring batch on application deployed on WebSphere. When I run the batch using Eclipse all runs fine but when I run the same batch in deployed application on WebSphere it gives error
com.thoughtworks.paranamer.ParameterNamesNotFoundException: Parameter names not found for executeMethod
at com.thoughtworks.paranamer.BytecodeReadingParanamer$TypeCollector.getParameterNamesForMethod(BytecodeReadingParanamer.java:209)
I checked source code of paranamer BytecodeReadingParanamer class and it says
if (!collector.isDebugInfoPresent()) {
if (throwExceptionIfMissing) {
throw new ParameterNamesNotFoundException("Parameter names not found for " + methodName);
} else {
return Paranamer.EMPTY_NAMES;
}
}
I believe it means that the Java class was not compiled with debug information (-g flag?) on WebSphere whereas in Eclipse, I have this information.
How can I correct this error on WebSphere? Do we have a add debug information in Java compiled classes flag?
Thank #minus the issue was indeed with the compiler as there was some bug in the compiler server. There was not anything wrong with paranamer or code itself. The bug of compiler had to be fixed.
Windows Scenario :-
I have a small piece of code which gets me the location of a specific folder in the directory. The code is as given below:
browserPath = this.EnginePath + "\\Chrome_Selenium\\" + "chromedriver.exe";
This gets me the exact path : D:\Engine\Test
I am trying to use the same logic to get the path in linux machine.
The path where the Engine and Chrome Driver is stored in my linux machine (VM) is
/root/Engine/Chrome_Selenium
Now the linux part :-
I am using the following piece of code to get that
browserPath = this.EnginePath + "/Chrome_Selenium/" + "chromedriver";
The path this piece of code fetches is
/root/Engine/.\Chrome_Selenium\chromedriver
Can you please help me understand why the "/.\" is appearing in the path?
I am guessing the reason why ./ is added is because in linux in order to execute a script in the present working directory you need to address it this way: ./script instead of script. Somehow it is attached even in cases where it is not needed (execution in other folder)
As for the main part as Alfe mentioned it does not make any different at the first place.
I will like to setup performance monitoring on an application running on Railo 4 using New Relic. I have consulted the java docs on Railo, Railo google groups, etc but no one seems to have a perfect step by step.
Here is what I have done so far:
Extracted newrelic into Railo's install folder.
Added this line to setenv.sh
export JAVA_OPTS="$JAVA_OPTS -javaagent:c/railo/newrelic/newrelic.jar"
Restarted the Railo-Tomcat service
Added this line to the onapplicationstart function
application.NewRelic = createObject( "java", "com.newrelic.api.agent.NewRelic" );
Added this line to the onrequeststart function
if ( structKeyExists( application, "NewRelic" ) ) {
application.NewRelic.setTransactionName( "CFML", CGI.SCRIPT_NAME );
}
My application is still not sending metrics to New Relic. I will appreciate a step by step instruction of what to do as I can't seem to find that anywhere else and I have no idea what to do.
You can't use setenv.sh on Windows. Instead modify the catalina.bat file, or use the Configure Tomcat utility in the Start Menu to set the javaagent option. These steps can be found in more detail in the New Relic documentation
We have more detailed instructions for installing with our supported platforms and frameworks in our documentation. To see a list of the supported frameworks we are compatible with check out https://docs.newrelic.com/docs/java/new-relic-for-java#h2-compatibility
We may be able to work with the Tomcat portion of your environment and you can find helpful installation information at https://docs.newrelic.com/docs/java/java-agent-manual-installation
Should you run into any obstacles, I suggest opening a ticket at http://support.newrelic.com
I am trying to configure the loggin to my web application.
This is where I want my application to put the logs:
C:\installs\JBossServer\jboss-6-0\server\default\log\kiche
If I do the following in the log4J.properties, the logs are created fine:
log4j.appender.R.File =C:\\installs\\JBossServer\\jboss-6-0\\server\\default\\log\\kiche\\kicheapp.log
I have an environment variable
JOBSS_HOME=C:\installs\JBossServer\jboss-6-0
And when I do like following in the log4J.properties, it not working.
log4j.appender.R.File=${JBOSS_HOME}\\server\\default\\log\\kiche\\kicheapp.log
Can someone please help me, I want to use JBOSS_HOME, so that its not hardcoded.
I am using JBOSS as a webserver.
Any help will be greatly appreciated.
Regards
Adofo
Maybe better is to edit jboss-log4j.xml ?
You should try :
JBOSS_HOME=C:\\installs\\JBossServer\\jboss-6-0
and also :
JBOSS_HOME=C:/installs/JBossServer/jboss-6-0 (change log4j.appender.R.File accordingly with "/" instead of "\\")
Also, is there a typo in your question or in your variable ? (JBOSS_HOME vs JOBSS_HOME)
log4J.properties cannot access the environment variables directly. Instead , you should use java system properties to do the substitution.
Tomcat 's start up script has the option -D<name>[=<value>] to set a system property .Please try to start the tomcat by using run.sh -DJBOSS_HOME=C:\installs\JBossServer\jboss-6-0