3

I have a 3rd-party developed big complex application full of java.util.logging.Logger#finer() calls.

Normally I use log4j and sl4j for logging, and I don't know very much of java.util.logging, even less about all the configuration details and possibilities.

Every single google about "java.util.logging" points to a full explanation about streams handlers, formatters, levels. Everyone assumes I really care about all this stuff (it is a reasonable assumption actually). But I couldn't care less.

I'm not really interested in separating logs per file, or file rotation, zipping, email, remote log etc. I'm also not concerned about log level and message formatting thrills.

All I want to do is to run this application with all available log messages spitting to stdout.

Is there an easy simple direct way to do this?

Something like jvmargs -Djava.util.logging.level=FINEST -Djava.util.logging.to=stdout. Or maybe some simple file dropped into some location in the classpath?

Progman
  • 16,827
  • 6
  • 33
  • 48
rslemos
  • 2,454
  • 22
  • 32
  • 2
    You might want to install a JUL to SLF4J bridge, see https://stackoverflow.com/questions/9117030/jul-to-slf4j-bridge – Progman Aug 03 '22 at 18:25
  • JUL does use a properties file, but I agree, adding the bridge would be better. Although, then the source code would still need changed to actually use slf4j classes, I believe – OneCricketeer Aug 03 '22 at 18:28
  • I don't have the source code, so any recommendation to change it is a non-starter. If I had this possibility I would change everything to `System.out.println`. – rslemos Aug 03 '22 at 19:01
  • I can't believe the easiest way is to add yet another library to the classpath (and perhaps configure it). But... well... I'll git it a try. – rslemos Aug 03 '22 at 19:02
  • You should write your own configuration file and tell the `LogManager` to use it. – user207421 Aug 03 '22 at 23:53

1 Answers1

2

All I want to do is to run this application with all available log messages spitting to stdout

Don't do this in production but it is the fast, easy, hacky way:

Edit the logging.properties file located in java/conf. E.G. /usr/lib/jvm/default-java/conf/logging.properties

That file is setup to attach a ConsoleHandler to the root logger which is what you want to do this. You just need to adjust the levels to see the output. This is a global change so be aware.

Edit that file and:

  • Change .level= INFO -> .level=ALL
  • Change java.util.logging.ConsoleHandler.level = INFO to java.util.logging.ConsoleHandler.level = ALL
  • Save the changes and restart your app.

The recommended way:

Most JVMs are not in your control (production/dev server) so you can instead copy that file to a location you own and use the java.util.logging.config.file system property.

E.G. -Djava.util.logging.config.file=/home/myuser/myapp/logging.properties

That way you are free to make changes that are local to your program and not global to the machine.

jmehrens
  • 10,580
  • 1
  • 38
  • 47
  • You should not edit the Java configuration. You should write your own configuration file and tell the `LogManager` to use it. – user207421 Aug 03 '22 at 23:53
  • @user207421 For sure. However, I think context matters here. The OP just wants something easy and quick. I could put a disclaimer in the answer. – jmehrens Aug 04 '22 at 00:08