3

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.

Pedantic
  • 1,368
  • 10
  • 39
  • 70
  • Could you please tell use exactly where you are putting your log4j.properties, how you are deploying your application (through a war?) and exactly the error you're getting. Thanks. – Matthew Farwell Sep 12 '11 at 13:35
  • actually this is SOA application.so we need to deploy sar(jar file). last time I added a jar file that was containing the log4j.properties and it was working. then I changed my envioronment and its stopped, I created one more jar file with only log4j.properties, it is not working. now I have tried by putting in classes , src folders also, its giving me warning while server is stating ,for some appender "wsif" even we are not using this appender also. too much confused. – Pedantic Sep 12 '11 at 14:55
  • Have you tried running weblogic with -Dlog4j.debug. This will tell you where it is looking for it's configuration. – Matthew Farwell Sep 13 '11 at 08:36
  • Thanks a lot, I manage to debug. Now I found that there is another log4j.properties file is placed by enterprise manager (em) application. is getting overriding our log4j.properties. now will you please help me how to set my log4j.properties while invoking server so both file will work. – Pedantic Sep 13 '11 at 10:44

4 Answers4

3

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!

Festus Tamakloe
  • 11,231
  • 9
  • 53
  • 65
anjanb
  • 12,999
  • 18
  • 77
  • 106
  • You've posted 230 answers, and all them of them contain horrible formatting and misuse inline HTML elements. Please, *please* take a minute and learn to use the [markdown editor](http://stackoverflow.com/editing-help). You should never actually have to use `
    ` tags in your posts if you're using the editor correctly.
    – user229044 Jul 26 '12 at 17:21
  • meagar -- that's harsh but I'll learn from it what I can! I will learn the markdown editor. thank you. – anjanb Jul 31 '12 at 14:20
  • Note: This method globalizes this particular log4j property file for every application deployed on WLS and even weblogic itself if weblogic is configured to use log4j. This method is not recommended at all in multi-application environments. Instead, package the log4j.properties file within their own jar/war/ear – Abid Mar 11 '14 at 08:28
2

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.

Community
  • 1
  • 1
Matthew Farwell
  • 60,889
  • 18
  • 128
  • 171
  • Hi, I have tried all combination. still not come up. please suggest from where the weblogic server is supposed to read log4j.properties file.... thanks – Pedantic Sep 12 '11 at 13:10
1

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.

Shawn Chin
  • 84,080
  • 19
  • 162
  • 191
-1

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.

Yogesh Kulkarni
  • 859
  • 1
  • 10
  • 19
  • Hi, I did the same as you ask. and keep my log4j.properties in jar file and config folder of domain. then I restart the server.still I am facing the same problem.. thanks – Pedantic Sep 12 '11 at 11:16
  • 3
    -1 You shouldn't copy the log4j into your servers configuration. It works perfectly well as part of the war. If you copy it into your server configuration, then it will be on the server classpath, which is not necessarily good for any other applications on the server. – Matthew Farwell Sep 12 '11 at 11:37
  • This is like screwing up your environment – Abid Mar 11 '14 at 08:30