0

I have a server application using CXF as a framework. I setup CXF via Spring, just by XML files, without any Java code.

I would like to log some internals of my server application to the application server's log file. Currently I do this just by calling System.out.println(), but I would like to use a logging framework/library like java.util.logging (since CXF already uses java.util.logging).

What is the recommended way to do this? How can I configure my java.util.logging Logger? Is it possible to use the same logging.properties as CXF uses?

I currently receive my Logger instance by calling Logger.getLogger(Server.class.getName()). Is this a good way to do this?

I tried to search the Internet about this, but I can only find ways to enable logging of the CXF framework itself, but I want to use logging in my own code.

Manuel Faux
  • 2,317
  • 5
  • 24
  • 35

1 Answers1

0

I found an example in the CXF samples.

Just define the logger as usual:

private static final Logger LOG = Logger.getLogger(My_Class.class.getPackage().getName());

The logging.properties file goes to WEB-INF/classes/logging.properties, like:

handlers = java.util.logging.ConsoleHandler

.handlers = java.util.logging.ConsoleHandler
.level = INFO

java.util.logging.ConsoleHandler.level = FINEST
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
java.util.logging.SimpleFormatter.format="%4$s: %5$s [%1$tc]%n"

com.example.My_Class.level = FINE
Manuel Faux
  • 2,317
  • 5
  • 24
  • 35