3

I am trying to get Weblogic 12c to do logging separately for application instead of writing everything to server logs.

I am using java.util.logging as follows:

private static final Logger log = Logger.getLogger(ReceiveController.class.getName());
...
log.info("Initializing...");

This is my weblogic.xml:

<?xml version="1.0" encoding="UTF-8"?>
<weblogic-web-app xmlns="http://xmlns.oracle.com/weblogic/weblogic-web-app">
    <context-root>mywebapp</context-root>
    <logging>
        <log-filename>mywebapp.log</log-filename>
        <logging-enabled>true</logging-enabled> <!--true/false - no difference-->
    </logging>
</weblogic-web-app>

Log file mywebapp.log gets created, but logs still goes to AdminServer.log.

What I expect: Logs of mywebapp to go to mywebapp.log, and not to AdminServer.log.

Also, at https://docs.oracle.com/cd/E24329_01/web.1211/e21049/weblogic_xml.htm#i1063198 it says "The full address of the filename is required.", but file gets created even if only filename is specified. mywebapp.log is empty even if I provide full path.

UPDATE. The question is not about separating of log messages by the logger name. For example we have two applications based on Spring Framework. In both cases the logger name starts with something like "org.springframework". The question is how to separate messages even if the logger name is the same.

For example Tomcat uses customised LogManager:

Apache Tomcat has its own implementation of several key elements of java.util.logging API. This implementation is called JULI. The key component there is a custom LogManager implementation, that is aware of different web applications running on Tomcat (and their different class loaders). It supports private per-application logging configurations. It is also notified by Tomcat when a web application is unloaded from memory, so that the references to its classes can be cleared, preventing memory leaks.

30thh
  • 10,861
  • 6
  • 32
  • 42
  • I didn't find where it is documented, but messages logged by ServletContext.log(...) method are written into the application log. It is the only way I found, how the software developer can write something into this log (tried on Weblogic 14c). – 30thh Dec 31 '21 at 06:48

1 Answers1

-1

The default configuration for java.util.logging is in $JAVA_HOME/jre/lib/logging.properties. It should contain the following parameters:

handlers= java.util.logging.ConsoleHandler
.level= INFO
java.util.logging.ConsoleHandler.level = INFO
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
com.xyz.foo.level = SEVERE

If you want to force the use of a different configuration file you have to add the startup paramenter

 -Djava.util.logging.config.file=<path to configuration file>

If you want all the logs you should set java.util.logging.ConsoleHandler.level to ALL. com.xyz.foo is a dummy logger. You can have more in your configuration file. If you want to point to that logger in your code you should use something like:

LogManager logManager = LogManager.getLogManager();
Logger log = logManager.getLogger("com.xyz.foo");

If you want to log to a file you should use the FileHandler, so your config file should look like:

handlers= java.util.logging.FileHandler
java.util.logging.FileHandler.pattern=<path to your log file>
java.util.logging.FileHandler.limit=50000
java.util.logging.FileHandler.count=1
   
java.util.logging.FileHandler.formatter=java.util.logging.SimpleFormatter
com.xyz.foo.level = FINEST
Saxon
  • 739
  • 3
  • 6
  • AFAIS it won't solve the problem. The question is how to split log messages of different JEE applications deployed on the server. – 30thh Dec 31 '21 at 06:30
  • This is different from the original bountied question. If you want multiple files for different distributions you can configure file handlers programmatically for your loggers. Look at some example at the link https://www.tabnine.com/code/java/classes/java.util.logging.FileHandler Anyway the best solution is to use logback or log4j2, latest revisions. – Saxon Dec 31 '21 at 14:18
  • An application includes not only the logger created by the developer, but lot of loggers created by third party library (for example Spring Framework). I don't know a way how can I manipulate all that logger for only a single web application without creating a own customized `LogManager`. – 30thh Jan 03 '22 at 09:52