# ERROR StatusLogger Unable to locate a logging implementation, using SimpleLogge

## Details

• Type: Question
• Status: Closed
• Priority: Blocker
• Resolution: Fixed
• Affects Version/s: 2.0-beta7
• Fix Version/s:
• Component/s:
• Labels:
• Environment:

windows7

## Description

I have problem to make the logging work with the log4j2.xml when packing into jar file.

I have launcher.jar which calls oamcli.jar(has logging implementation and log is working in eclipse)

How ever when I try to run :

java -Dlog4j.configurationFile=path\to\log4j2.xml -cp "launcher.jar; lib*" .....

I got a "ERROR StatusLogger Unable to locate a logging implementation, using SimpleLogger"

Thanks!

## Activity

Hide
Remko Popma added a comment - - edited
• should your classpath not be: -cp "launcher.jar;lib/*" ? (with a slash between lib and the star, and no space between ';' and 'lib'?)
• does the lib directory contain log4j-core-2.0-beta8.jar?
Show
Remko Popma added a comment - - edited should your classpath not be: -cp "launcher.jar;lib/*" ? (with a slash between lib and the star, and no space between ';' and 'lib'?) does the lib directory contain log4j-core-2.0-beta8.jar?
Hide
wei wang added a comment -

The command can be run without any problem and the lib included log4j-core-2.0-beta8.jar.

The problem is when try to run launcher.jar (no logging implementation) and start oamcli.jar(with logging implementation). The log4j2.xml does not work any more.

I do not know why? Should I implement the logging in launcher.jar source code as well in order to activate the log4j2?

Show
wei wang added a comment - The command can be run without any problem and the lib included log4j-core-2.0-beta8.jar. The problem is when try to run launcher.jar (no logging implementation) and start oamcli.jar(with logging implementation). The log4j2.xml does not work any more. I do not know why? Should I implement the logging in launcher.jar source code as well in order to activate the log4j2?
Hide
wei wang added a comment -

Hi again,

If I only run oamcli.jar alone, the logging log4j2.xml is working fine!

Show
wei wang added a comment - Hi again, If I only run oamcli.jar alone, the logging log4j2.xml is working fine!
Hide
Remko Popma added a comment -

I guess it depends on what your launcher thing does...
Are you starting another java process from the first java process?
If that's the case are you passing the correct classpath and system properties to your child process?

Show
Remko Popma added a comment - I guess it depends on what your launcher thing does... Are you starting another java process from the first java process? If that's the case are you passing the correct classpath and system properties to your child process?
Hide
wei wang added a comment -

How to passing the properties?

I have the logging implementation in the child process and jar file with the log4j2.xml when build.
[esekilxxen1312 /proj/oamwind/eweiwan_delivery/CLITOOL-SIM_CXS123456_X/CLITOOL_CXP2000001/CLITOOLWRAPPER_CXC1111111/emcli ]jar tvf oamCliClient.jar
2572 Tue Aug 20 10:15:08 CEST 2013 META-INF/MANIFEST.MF
2415 Tue Aug 20 10:15:08 CEST 2013 META-INF/EMAS.SF
2383 Tue Aug 20 10:15:08 CEST 2013 META-INF/EMAS.DSA
0 Tue Aug 20 10:15:10 CEST 2013 META-INF/
0 Tue Aug 20 10:15:08 CEST 2013 com/
0 Tue Aug 20 10:15:08 CEST 2013 com/ericsson/
0 Tue Aug 20 10:15:08 CEST 2013 com/ericsson/rbs/
0 Tue Aug 20 10:15:08 CEST 2013 com/ericsson/rbs/clitool/
0 Tue Aug 20 10:15:08 CEST 2013 com/ericsson/rbs/clitool/com/
0 Tue Aug 20 10:15:08 CEST 2013 com/ericsson/rbs/clitool/common/
0 Tue Aug 20 10:15:08 CEST 2013 com/ericsson/rbs/clitool/launch/
0 Tue Aug 20 10:15:08 CEST 2013 com/ericsson/rbs/clitool/moshell/
0 Tue Aug 20 10:15:08 CEST 2013 com/ericsson/rbs/clitool/session/
1259 Tue Aug 20 10:15:08 CEST 2013 com/ericsson/rbs/clitool/HelloWorld.class
3930 Tue Aug 20 10:15:08 CEST 2013 com/ericsson/rbs/clitool/com/CommandThread.class
410 Tue Aug 20 10:15:08 CEST 2013 com/ericsson/rbs/clitool/com/CommandThreadFactory.class
857 Tue Aug 20 10:15:08 CEST 2013 com/ericsson/rbs/clitool/com/ConnectionManager.class
2132 Tue Aug 20 10:15:08 CEST 2013 com/ericsson/rbs/clitool/com/ConnectionManagerFactory.class
2942 Tue Aug 20 10:15:08 CEST 2013 com/ericsson/rbs/clitool/com/ConnectionManagerForLinux.class
8879 Tue Aug 20 10:15:08 CEST 2013 com/ericsson/rbs/clitool/com/ConnectionManagerForWindows.class
1199 Tue Aug 20 10:15:08 CEST 2013 com/ericsson/rbs/clitool/com/PortHandler$1.class 4663 Tue Aug 20 10:15:08 CEST 2013 com/ericsson/rbs/clitool/com/PortHandler.class 5525 Tue Aug 20 10:15:08 CEST 2013 com/ericsson/rbs/clitool/common/Trace.class 143 Tue Aug 20 10:15:08 CEST 2013 com/ericsson/rbs/clitool/common/Utils.class 2868 Tue Aug 20 10:15:08 CEST 2013 com/ericsson/rbs/clitool/launch/CliWrapper.class 1352 Tue Aug 20 10:15:08 CEST 2013 com/ericsson/rbs/clitool/launch/LauncherData.class 1310 Tue Aug 20 10:15:08 CEST 2013 com/ericsson/rbs/clitool/moshell/MoShellData.class 461 Tue Aug 20 10:15:08 CEST 2013 com/ericsson/rbs/clitool/moshell/MoShellManager.class 600 Tue Aug 20 10:15:08 CEST 2013 com/ericsson/rbs/clitool/moshell/MoShellManagerFactory.class 2295 Tue Aug 20 10:15:08 CEST 2013 com/ericsson/rbs/clitool/moshell/MoShellManagerImpl.class 379 Tue Aug 20 10:15:08 CEST 2013 com/ericsson/rbs/clitool/session/Session.class 941 Tue Aug 20 10:15:08 CEST 2013 com/ericsson/rbs/clitool/session/SessionFactory.class 5956 Tue Aug 20 10:15:08 CEST 2013 com/ericsson/rbs/clitool/session/SessionImpl.class 1196 Tue Aug 20 10:15:08 CEST 2013 log4j2.xml 27 Tue Aug 20 10:15:08 CEST 2013 oamCliClient.properties [esekilxxen1312 /proj/oamwind/eweiwan_delivery/CLITOOL-SIM_CXS123456_X/CLITOOL_CXP2000001/CLITOOLWRAPPER_CXC1111111/emcli ] When the parent process call the child process, the how the log4j2 will work? Show wei wang added a comment - How to passing the properties? I have the logging implementation in the child process and jar file with the log4j2.xml when build. [esekilxxen1312 /proj/oamwind/eweiwan_delivery/CLITOOL-SIM_CXS123456_X/CLITOOL_CXP2000001/CLITOOLWRAPPER_CXC1111111/emcli ] jar tvf oamCliClient.jar 2572 Tue Aug 20 10:15:08 CEST 2013 META-INF/MANIFEST.MF 2415 Tue Aug 20 10:15:08 CEST 2013 META-INF/EMAS.SF 2383 Tue Aug 20 10:15:08 CEST 2013 META-INF/EMAS.DSA 0 Tue Aug 20 10:15:10 CEST 2013 META-INF/ 0 Tue Aug 20 10:15:08 CEST 2013 com/ 0 Tue Aug 20 10:15:08 CEST 2013 com/ericsson/ 0 Tue Aug 20 10:15:08 CEST 2013 com/ericsson/rbs/ 0 Tue Aug 20 10:15:08 CEST 2013 com/ericsson/rbs/clitool/ 0 Tue Aug 20 10:15:08 CEST 2013 com/ericsson/rbs/clitool/com/ 0 Tue Aug 20 10:15:08 CEST 2013 com/ericsson/rbs/clitool/common/ 0 Tue Aug 20 10:15:08 CEST 2013 com/ericsson/rbs/clitool/launch/ 0 Tue Aug 20 10:15:08 CEST 2013 com/ericsson/rbs/clitool/moshell/ 0 Tue Aug 20 10:15:08 CEST 2013 com/ericsson/rbs/clitool/session/ 1259 Tue Aug 20 10:15:08 CEST 2013 com/ericsson/rbs/clitool/HelloWorld.class 3930 Tue Aug 20 10:15:08 CEST 2013 com/ericsson/rbs/clitool/com/CommandThread.class 410 Tue Aug 20 10:15:08 CEST 2013 com/ericsson/rbs/clitool/com/CommandThreadFactory.class 857 Tue Aug 20 10:15:08 CEST 2013 com/ericsson/rbs/clitool/com/ConnectionManager.class 2132 Tue Aug 20 10:15:08 CEST 2013 com/ericsson/rbs/clitool/com/ConnectionManagerFactory.class 2942 Tue Aug 20 10:15:08 CEST 2013 com/ericsson/rbs/clitool/com/ConnectionManagerForLinux.class 8879 Tue Aug 20 10:15:08 CEST 2013 com/ericsson/rbs/clitool/com/ConnectionManagerForWindows.class 1199 Tue Aug 20 10:15:08 CEST 2013 com/ericsson/rbs/clitool/com/PortHandler$1.class 4663 Tue Aug 20 10:15:08 CEST 2013 com/ericsson/rbs/clitool/com/PortHandler.class 5525 Tue Aug 20 10:15:08 CEST 2013 com/ericsson/rbs/clitool/common/Trace.class 143 Tue Aug 20 10:15:08 CEST 2013 com/ericsson/rbs/clitool/common/Utils.class 2868 Tue Aug 20 10:15:08 CEST 2013 com/ericsson/rbs/clitool/launch/CliWrapper.class 1352 Tue Aug 20 10:15:08 CEST 2013 com/ericsson/rbs/clitool/launch/LauncherData.class 1310 Tue Aug 20 10:15:08 CEST 2013 com/ericsson/rbs/clitool/moshell/MoShellData.class 461 Tue Aug 20 10:15:08 CEST 2013 com/ericsson/rbs/clitool/moshell/MoShellManager.class 600 Tue Aug 20 10:15:08 CEST 2013 com/ericsson/rbs/clitool/moshell/MoShellManagerFactory.class 2295 Tue Aug 20 10:15:08 CEST 2013 com/ericsson/rbs/clitool/moshell/MoShellManagerImpl.class 379 Tue Aug 20 10:15:08 CEST 2013 com/ericsson/rbs/clitool/session/Session.class 941 Tue Aug 20 10:15:08 CEST 2013 com/ericsson/rbs/clitool/session/SessionFactory.class 5956 Tue Aug 20 10:15:08 CEST 2013 com/ericsson/rbs/clitool/session/SessionImpl.class 1196 Tue Aug 20 10:15:08 CEST 2013 log4j2.xml 27 Tue Aug 20 10:15:08 CEST 2013 oamCliClient.properties [esekilxxen1312 /proj/oamwind/eweiwan_delivery/CLITOOL-SIM_CXS123456_X/CLITOOL_CXP2000001/CLITOOLWRAPPER_CXC1111111/emcli ] When the parent process call the child process, the how the log4j2 will work?
Hide
wei wang added a comment -

By the way, the path should be lib*

Show
wei wang added a comment - By the way, the path should be lib*
Hide
wei wang added a comment -

Hi Remo, path I mean should be lib
* why / could not be shown?

Show
wei wang added a comment - Hi Remo, path I mean should be lib * why / could not be shown?
Hide
wei wang added a comment -

The complete cmd:
"C:\Program Files (x86)\Java\jre6\bin\"java -Dlog4j.configurationFile="C:\Users\eweiwan\log4j2.xml" -cp "C:\Users\eweiwan\Ericsson\starter\launcher.jar; C:\Users\eweiwan*" se.ericsson.security.starter.Starter /emcli/clitool_config.xml icon_EM_16.gif hostname=147.214.45.181:9772

Show
wei wang added a comment - The complete cmd: "C:\Program Files (x86)\Java\jre6\bin\"java -Dlog4j.configurationFile="C:\Users\eweiwan\log4j2.xml" -cp "C:\Users\eweiwan\Ericsson\starter\launcher.jar; C:\Users\eweiwan*" se.ericsson.security.starter.Starter /emcli/clitool_config.xml icon_EM_16.gif hostname=147.214.45.181:9772
Hide
wei wang added a comment -

The result is:
2013-aug-20 14:00:49 se.ericsson.security.launcher.Launcher runApplicationOrResourc
INFO: Required EM Launcher: CXC1735219 R9AB
ERROR StatusLogger Unable to locate a logging implementation, using SimpleLogger

Show
wei wang added a comment - The result is: 2013-aug-20 14:00:49 se.ericsson.security.launcher.Launcher runApplicationOrResourc INFO: Required EM Launcher: CXC1735219 R9AB ERROR StatusLogger Unable to locate a logging implementation, using SimpleLogger
Hide
wei wang added a comment -

Hi Remo,

I have even tried with the hardcoded configuration in source code:

static

{ System.setProperty(XMLConfigurationFactory.CONFIGURATION_FILE_PROPERTY, System.getProperty("user.home")); }

and put the log4j2.xml at user.home .

But still did not solve the problem!

Show
wei wang added a comment - Hi Remo, I have even tried with the hardcoded configuration in source code: static { System.setProperty(XMLConfigurationFactory.CONFIGURATION_FILE_PROPERTY, System.getProperty("user.home")); } and put the log4j2.xml at user.home . But still did not solve the problem!
Hide
Ralph Goers added a comment -

The problem isn't that it can't find your configuration file. It can't seem to find log4j-core. The API locates logging implementations by searching for META-INF/log4j-provider.properties in the classpath. The log4j-core jar has the file inside it. For some reason in your setup it doesn't seem to be finding the file.

Show
Ralph Goers added a comment - The problem isn't that it can't find your configuration file. It can't seem to find log4j-core. The API locates logging implementations by searching for META-INF/log4j-provider.properties in the classpath. The log4j-core jar has the file inside it. For some reason in your setup it doesn't seem to be finding the file.
Hide
wei wang added a comment -

Hi Ralph,

In my -cp "C:\Users\eweiwan*" exists log4j-core and log4j-api jar files.

log4j-1.2-api-2.0-beta8.jar
log4j-core-2.0-beta8.jar

Will that be enough?

Show
wei wang added a comment - Hi Ralph, In my -cp "C:\Users\eweiwan*" exists log4j-core and log4j-api jar files. log4j-1.2-api-2.0-beta8.jar log4j-core-2.0-beta8.jar Will that be enough?
Hide
wei wang added a comment -

C:\Users\eweiwan*

Show
wei wang added a comment - C:\Users\eweiwan*
Hide
wei wang added a comment -

C:\Users\eweiwan forwardslash *

Show
wei wang added a comment - C:\Users\eweiwan forwardslash *
Hide
wei wang added a comment -

C:\Users\eweiwan
*

Show
wei wang added a comment - C:\Users\eweiwan *
Hide
Ralph Goers added a comment - - edited

Can you create a sample app that has this problem and attach it to this issue? I'd really need to see what launcher.jar is doing to know what is going on. Does it have any logging that you can enable?

Show
Ralph Goers added a comment - - edited Can you create a sample app that has this problem and attach it to this issue? I'd really need to see what launcher.jar is doing to know what is going on. Does it have any logging that you can enable?
Hide
wei wang added a comment -

Hi Ralph,

The launcher.jar has no log4j2 logging implementation. It calls oamCli.jar which has log4j2 implementation in start thread. At the entrance class I had code :

static

{ System.setProperty(XMLConfigurationFactory.CONFIGURATION_FILE_PROPERTY, System.getProperty("user.home")+ File.Separator +"log4j2.xml"); }

so the log4j2.xml file is located at "user.home"

I even used -Dlog4j.configurationFile="C:\Users\eweiwan\log4j2.xml"

The error message is still printed out by the simplelog at console.

Do you have an example of cmd which set the classpath for log4j-core*.jar that worked ?

Show
wei wang added a comment - Hi Ralph, The launcher.jar has no log4j2 logging implementation. It calls oamCli.jar which has log4j2 implementation in start thread. At the entrance class I had code : static { System.setProperty(XMLConfigurationFactory.CONFIGURATION_FILE_PROPERTY, System.getProperty("user.home")+ File.Separator +"log4j2.xml"); } so the log4j2.xml file is located at "user.home" I even used -Dlog4j.configurationFile="C:\Users\eweiwan\log4j2.xml" The error message is still printed out by the simplelog at console. Do you have an example of cmd which set the classpath for log4j-core*.jar that worked ?
Hide
Remko Popma added a comment -

You're using launcher to start a child process.
You want to do logging in the child process, so the api and core jars need to be in the classpath of the child process.

Lets start by finding out what the classpath of your child process is.
Somewhere in your child process, can you print the system property for the java classpath to the console? Does it contain the log4j api and core jars?

Show
Remko Popma added a comment - You're using launcher to start a child process. You want to do logging in the child process, so the api and core jars need to be in the classpath of the child process . Lets start by finding out what the classpath of your child process is. Somewhere in your child process, can you print the system property for the java classpath to the console? Does it contain the log4j api and core jars?
Hide
Remko Popma added a comment -

Here is an example launcher that makes sure the log4j jars are in the classpath of the child process:

package a;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

class ChildProcess {
public static void main(String[] args) throws Exception {
Logger log = LogManager.getLogger(ChildProcess.class);
log.error("Hello world!");
}
}

public class Launcher {

public static void main(String[] args) throws Exception {
ProcessBuilder pb = new ProcessBuilder( //
"java", //
"-Dlog4j.configurationFile=log4j2.xml", //

// THIS IS IMPORTANT!
// Log4j jars must be in classpath of CHILD process!
//
// One (easy) way to do this is to pass the classpath of
// the parent process to child process...
// Then start laucher with the log4j jars in the classpath.
"-cp", System.getProperty("java.class.path"), //
//
// Another way would be to set the individual jars & directories...
//"-cp", "lib/log4j-api-2.0-beta8.jar;lib/log4j-core-2.0-beta8.jar",

// class name of the child process
ChildProcess.class.getName()
);

pb.redirectErrorStream(true); // merge System.out and System.err
final Process process = pb.start();

final boolean[] stop = { false };
printProcessOutput(process, stop);
process.waitFor();
stop[0] = true;
}

private static Thread printProcessOutput(final Process process,
final boolean[] stop) {

@Override
public void run() {
process.getInputStream()));
try {
String line = null;
while (!stop[0] && (line = in.readLine()) != null) {
System.out.println(line);
}
} catch (Exception ignored) {
}
}
};
t.start();
return t;
}
}


This child process logs correctly to the console. Here is the command:

java -cp bin;lib/log4j-api-2.0-beta8.jar;lib/log4j-core-2.0-beta8.jar a.Launcher

I get the following output:

09:37:51.310 [main] ERROR a.ChildProcess - Hello world!

Show
Remko Popma added a comment - Here is an example launcher that makes sure the log4j jars are in the classpath of the child process: package a; import java.io.BufferedReader; import java.io.InputStreamReader; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; class ChildProcess { public static void main( String [] args) throws Exception { Logger log = LogManager.getLogger(ChildProcess.class); log.error( "Hello world!" ); } } public class Launcher { public static void main( String [] args) throws Exception { ProcessBuilder pb = new ProcessBuilder( // "java" , // "-Dlog4j.configurationFile=log4j2.xml" , // // THIS IS IMPORTANT! // Log4j jars must be in classpath of CHILD process! // // One (easy) way to do this is to pass the classpath of // the parent process to child process... // Then start laucher with the log4j jars in the classpath. "-cp" , System .getProperty( "java.class.path" ), // // // Another way would be to set the individual jars & directories... // "-cp" , "lib/log4j-api-2.0-beta8.jar;lib/log4j-core-2.0-beta8.jar" , // class name of the child process ChildProcess.class.getName() ); pb.redirectErrorStream( true ); // merge System .out and System .err final Process process = pb.start(); final boolean [] stop = { false }; printProcessOutput(process, stop); process.waitFor(); stop[0] = true ; } private static Thread printProcessOutput( final Process process, final boolean [] stop) { Thread t = new Thread ( "OutputWriter" ) { @Override public void run() { BufferedReader in = new BufferedReader( new InputStreamReader( process.getInputStream())); try { String line = null ; while (!stop[0] && (line = in.readLine()) != null ) { System .out.println(line); } } catch (Exception ignored) { } } }; t.start(); return t; } } This child process logs correctly to the console. Here is the command: java -cp bin;lib/log4j-api-2.0-beta8.jar;lib/log4j-core-2.0-beta8.jar a.Launcher I get the following output: 09:37:51.310 [main] ERROR a.ChildProcess - Hello world!
Hide
wei wang added a comment -

I am running the jar at windows7, so if I set the environment variable %CLASSPATH% to where the log4j.jars, if I do not touch the laucher.jar source code, is there anyway to make it work?

I feel that we are almost there! Thx!

Show
wei wang added a comment - I am running the jar at windows7, so if I set the environment variable %CLASSPATH% to where the log4j.jars, if I do not touch the laucher.jar source code, is there anyway to make it work? I feel that we are almost there! Thx!
Hide
wei wang added a comment -

The difference is that my Child process packed in a jar file (with log4j2.xml) while in your example ,both parent and child are in the same package.

I will try to System.out.println(System.getProperty("java.class.path")) at child process;

Show
wei wang added a comment - The difference is that my Child process packed in a jar file (with log4j2.xml) while in your example ,both parent and child are in the same package. I will try to System.out.println(System.getProperty("java.class.path")) at child process;
Hide
wei wang added a comment -

Due to the reason, I could not change the launcher.jar source code. How to make the child process still working? Dynamically set the classpath in child process? I had tried to put the code in child class

static

{ System.setProperty(XMLConfigurationFactory.CONFIGURATION_FILE_PROPERTY, System.getProperty("user.home")+ File.Separator +"log4j2.xml"); }

It appeared that child process can find the log4j-core and api otherwise classnotFoundException will ocurr.

Show
wei wang added a comment - Due to the reason, I could not change the launcher.jar source code. How to make the child process still working? Dynamically set the classpath in child process? I had tried to put the code in child class static { System.setProperty(XMLConfigurationFactory.CONFIGURATION_FILE_PROPERTY, System.getProperty("user.home")+ File.Separator +"log4j2.xml"); } It appeared that child process can find the log4j-core and api otherwise classnotFoundException will ocurr.
Hide
Remko Popma added a comment -

Somewhere in your child process, can you print the system property for the java classpath to the console?
Is it the same as your environment variable %CLASSPATH%?

Show
Remko Popma added a comment - Somewhere in your child process, can you print the system property for the java classpath to the console? Is it the same as your environment variable %CLASSPATH%?
Hide
wei wang added a comment -

Hi Remko,

Now I come to the basic things you have mentioned from the very beginning! The -cp should not have any space after ";" after remove the space it works !!! Sorry

I will continue to look into how to deal with the lib\log4j-*.jar could be delivered with my child.jar(otherwise the user will have to download log4j2 package them by themselves).

I used ant to build the jar however, it is not allowed to have serveral META-INF built so I have to excludes=META-INF/*/ in the ant build which cause the problem for log4j to read the properties file in the lib.

I have unpacked the lib\log4j-*.jar and repack them again with the child.class. No compile error but missing log4j.properties in META-INFO ? (I did not know it is needed).

<zipfileset src="lib\log4j-core-2.0-beta7.jar" includes="*/.class excludes="META-INFO/*/" />"
<zipfileset src="lib\log4j-api-2.0-beta7.jar" includes="*/.class excludes="META-INFO/*/" />"

Show
wei wang added a comment - Hi Remko, Now I come to the basic things you have mentioned from the very beginning! The -cp should not have any space after ";" after remove the space it works !!! Sorry I will continue to look into how to deal with the lib\log4j-*.jar could be delivered with my child.jar(otherwise the user will have to download log4j2 package them by themselves). I used ant to build the jar however, it is not allowed to have serveral META-INF built so I have to excludes=META-INF/* / in the ant build which cause the problem for log4j to read the properties file in the lib. I have unpacked the lib\log4j-*.jar and repack them again with the child.class. No compile error but missing log4j.properties in META-INFO ? (I did not know it is needed). <zipfileset src="lib\log4j-core-2.0-beta7.jar" includes="* / .class excludes="META-INFO/* / " />" <zipfileset src="lib\log4j-api-2.0-beta7.jar" includes="* / .class excludes="META-INFO/* / " />"
Hide
wei wang added a comment -

Hi Remko,

I have print out the "classpath" and "java.class.path ", they are not the same!

However,I have the log4j2.xml built in the same path as the child.classes in the child.jar, but still could not detect the log4j2.xml

---------------------------------------------------------------------------------------
...
379 Tue Aug 20 10:15:08 CEST 2013 com/ericsson/rbs/clitool/session/Session.class
941 Tue Aug 20 10:15:08 CEST 2013 com/ericsson/rbs/clitool/session/SessionFactory.class
5956 Tue Aug 20 10:15:08 CEST 2013 com/ericsson/rbs/clitool/session/SessionImpl.class
1196 Tue Aug 20 10:15:08 CEST 2013 log4j2.xml <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<here
27 Tue Aug 20 10:15:08 CEST 2013 oamCliClient.properties
--------------------------------------------------------------------------------------------------

what makes it work is to edit in the child class source code with:

static

{ System.setProperty(XMLConfigurationFactory.CONFIGURATION_FILE_PROPERTY, System.getProperty("user.home")+ File.Separator +"log4j2.xml"); }

conclusion: If log4j2.xml packed in a jar file, it will not work! It must be specified at cmd -Dlog4j..... or to make a setting in the source code as above.
question: How to embed the external lib log4jxxx.jar in my child.jar so that logging would still work ? Any best practice there?

Show
wei wang added a comment - Hi Remko, I have print out the "classpath" and "java.class.path ", they are not the same! However,I have the log4j2.xml built in the same path as the child.classes in the child.jar, but still could not detect the log4j2.xml --------------------------------------------------------------------------------------- ... 379 Tue Aug 20 10:15:08 CEST 2013 com/ericsson/rbs/clitool/session/Session.class 941 Tue Aug 20 10:15:08 CEST 2013 com/ericsson/rbs/clitool/session/SessionFactory.class 5956 Tue Aug 20 10:15:08 CEST 2013 com/ericsson/rbs/clitool/session/SessionImpl.class 1196 Tue Aug 20 10:15:08 CEST 2013 log4j2.xml <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<here 27 Tue Aug 20 10:15:08 CEST 2013 oamCliClient.properties -------------------------------------------------------------------------------------------------- what makes it work is to edit in the child class source code with: static { System.setProperty(XMLConfigurationFactory.CONFIGURATION_FILE_PROPERTY, System.getProperty("user.home")+ File.Separator +"log4j2.xml"); } conclusion: If log4j2.xml packed in a jar file, it will not work! It must be specified at cmd -Dlog4j..... or to make a setting in the source code as above. question: How to embed the external lib log4jxxx.jar in my child.jar so that logging would still work ? Any best practice there?
Hide
Remko Popma added a comment -

if the log4j2.xml file is inside a jar, you could try to specify the location like this:
jar:file:/C:/path/to/jarfile.jar!path/in/jar/log4j2.xml

WARNING: I strongly recommend against unzipping the log4j jar files and zipping them back up into a custom jar! It is open source, you can use it any way you want of course, but I certainly don't want to support it...

The log4j jar files contain lots of other files, not just .class files. Log4j NEEDS those other files to work properly. Again, if you unzip the jars, strip out or change config files, and then zip the result back up into a custom file, I have no idea what will happen. It may work, it may not. Or even worse, it will work a little until after you ship to your users, and then your users run into problems because they run on different configurations than you imagined...

Show
Remko Popma added a comment - if the log4j2.xml file is inside a jar, you could try to specify the location like this: jar: file:/C:/path/to/jarfile.jar!path/in/jar/log4j2.xml WARNING: I strongly recommend against unzipping the log4j jar files and zipping them back up into a custom jar! It is open source, you can use it any way you want of course, but I certainly don't want to support it... The log4j jar files contain lots of other files, not just .class files. Log4j NEEDS those other files to work properly. Again, if you unzip the jars, strip out or change config files, and then zip the result back up into a custom file, I have no idea what will happen. It may work, it may not. Or even worse, it will work a little until after you ship to your users, and then your users run into problems because they run on different configurations than you imagined...
Hide
wei wang added a comment -

Thanks!

I'd like to have this solution:
static

{ System.setProperty(XMLConfigurationFactory.CONFIGURATION_FILE_PROPERTY, System.getProperty("user.home")+ File.Separator +"log4j2.xml"); }

Hope it will not have any side-effect.

Show
wei wang added a comment - Thanks! I'd like to have this solution: static { System.setProperty(XMLConfigurationFactory.CONFIGURATION_FILE_PROPERTY, System.getProperty("user.home")+ File.Separator +"log4j2.xml"); } Hope it will not have any side-effect.
Hide
Ralph Goers added a comment - - edited

I'm a bit confused. You said you would like the log4j2.xml inside of a jar. $user.home\log4j2.xml will never resolve into a path inside of a jar. Also, I am wondering if there is still a problem here that needs to be solved. The title of the issue is for being unable to locate the logging implementation but from what I can tell that has been resolved. Show Ralph Goers added a comment - - edited I'm a bit confused. You said you would like the log4j2.xml inside of a jar.$user.home\log4j2.xml will never resolve into a path inside of a jar. Also, I am wondering if there is still a problem here that needs to be solved. The title of the issue is for being unable to locate the logging implementation but from what I can tell that has been resolved.
Hide
wei wang added a comment -

Yes the problem has been solved, thanks for the your support.

Conclusion:

I will not build the lib log4jxxx.jar into my child.jar because of the potential risk mentioned by Remko.

I will put the log4jxxx.jar in my classpath and use $user.home\log4j2.xml to configure the logging. Show wei wang added a comment - Yes the problem has been solved, thanks for the your support. Conclusion: I will not build the lib log4jxxx.jar into my child.jar because of the potential risk mentioned by Remko. I will put the log4jxxx.jar in my classpath and use$user.home\log4j2.xml to configure the logging.
Hide
wei wang added a comment -

The the classpath and use lib separately(no jar in jar)

Show
wei wang added a comment - The the classpath and use lib separately(no jar in jar)

## People

• Assignee:
Unassigned
Reporter:
wei wang
0 Vote for this issue
Watchers:
3 Start watching this issue

## Dates

• Created:
Updated:
Resolved:

## Time Tracking

Estimated:
12h
Remaining:
12h
Logged:
Not Specified