Pedantic
Pedantic

Reputation: 1378

log4j is not working in weblogic server?

I am using weblogic 10.3.4, I am trying to write log with log4j. but at runtime my application is not getting any log4j.properties. even this is not generating any warning as "initialization of log4j has error".

I have tried my properties file to put in src folder, classes folder and then I created one jar and put it in domain lib. still its not picking. even when I am writing log with same jar in standalone application, its working fine.

please help me with valuable suggestions.

Upvotes: 3

Views: 24122

Answers (4)

Matthew Farwell
Matthew Farwell

Reputation: 61715

You need to either specify where the application should find its log4j.properties, or put it onto the classpath of the application. Where the classpath is varies, but in general WEB-INF/classes should work. Other options depend upon how you're deploying the application.

A better long term strategy is to configure your system so that you can change the log4j.properties depending upon the environment. When you're in production, you won't want all of the debug information to appear. Look at the answer to this question or this question for more ideas. One strategy is to define a variable on the command line which gets picked up and defines a directory which contains your configuration files. This works for Tomcat, but there may be other, better, strategies for Weblogic.

It is not a good idea to change the configuration of your server, in particular, don't replace the log4j.jar or log4j.properties in your server directories. The server will depend upon the version that it was designed to use, which may or may not be the same as your version. You can do everything you need to do by changing the war that you're deploying.

Upvotes: 2

anjanb
anjanb

Reputation: 13927

I tried the solution proposed at Oracle forums.

Excerpt from that link at Oracle forums:

I've only modified the scritp startWebLogic.cmd:

 set LOG4J_CONFIG_FILE=log4j.xml 
 set SAVE_JAVA_OPTIONS=%JAVA_OPTIONS% -Dlog4j.configuration=%LOG4J_CONFIG_FILE%

 @REM set SAVE_CLASSPATH=%CLASSPATH% 
 set SAVE_CLASSPATH=%CLASSPATH%;C:\Oracle\Middleware\user_projects\domains\domain\config

In this way I've put all the config folder inside the classpath, and I can use it in future to hold other libraries configuration files (for example oracle coherence config).

I tried this approach on a different properties file as well and that worked well!

Upvotes: 3

user1026870
user1026870

Reputation:

I have used this code:

    ClassLoader cl = this.getClass().getClassLoader();
    URL log4jCfg = cl.getResource(configFile);
    if (log4jCfg != null) {
        DOMConfigurator.configure(log4jCfg);
    }
log.info("log4j is now working on Web App.");

In my case, we used XML configuration:

log4jCfg = "mylog4j.xml";

In WebLogic, we were able to place such file (mylog4j.xml), equivalent to your log4j.properties file, at WebLogic's domain path (specific to the domain were we deploy). This means that domain folder belongs to your application's path. I just tested it with Web applications, I'm not sure if with SOA or EJB projects it works the same way.

Upvotes: 1

Yogesh Kulkarni
Yogesh Kulkarni

Reputation: 897

When you deploy any application on any server that application should use servers log4j jar.

So if you have added any log4j jar in your application jar/tar/ear, remove it and copy log4j.properties file in the conf folder of the server from where server is picking its configuration files. Or just copy your log4j property content in servers log4j property file.

Upvotes: -1

Related Questions