Friday, July 17, 2009

Writing to WebLogic Server Logs

For J2EE developers who are not familiar with WebLogic, you can write debug and error messages to the server logs very easily.

When to Write to WebLogic Server Logs

Any debug, warning or error messages relating to the server or infrastructure. For example, information or errors with the following:
  • Connecting to other components/systems.
  • Database access, setup, etc.
  • LDAP
  • HTTP request/response
  • Deployment dependencies
Do not write to the server logs if you are handling the following:
  • Unexpected user input
  • Application debug/info/warning messages. (Write these to your own application logs.)

How to do it

Writing to the WebLogic server logs is simple. Just use LoggingHelper to get a Logger object and print messages to your heart's content. Here is some example code:

Put this in the class declaration:

private static java.util.logging.Logger serverLogger = LoggingHelper.getServerLogger();

Use these throughout your code:

serverLogger.log(Level.INFO, "Hello World!");
serverLogger.warning("This is a warning.");
serverLogger.severe("Something bad has happened!");

If you need more information about these classes, try these links:

BEA provides quite a lot of information about logging here:

No comments:

Post a Comment