Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

What does each indexed field from `java.util.logging.SimpleFormatter.format` mean?

I keep seeing tutorials and explanations, all based on the standard javadoc.

For example:

java.util.logging.SimpleFormatter.format="%1$tc %2$s%n%4$s: %5$s%6$s%n"
This prints 2 lines where the first line includes the timestamp (1$) and the source (2$); the second line includes the log level (4$) and the log message (5$)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

So I guess that if (for whatever reason) I want to put the message before everything else, I just put 5$ at the beginning.

Where can I find a detailed explanation of what each of those numbered fields mean?

>Solution :

The JavaDocs you linked will show it as the function args, but if you ignore the first one the rest line up in place:

  1. date – a Date object representing event time of the log record.
  2. source – a string representing the caller, if available; otherwise, the logger’s name.
  3. logger – the logger’s name.
  4. level – the log level.
  5. message – the formatted log message returned from the Formatter.formatMessage(LogRecord) method. It uses java.text formatting and does not use the java.util.Formatter format argument.
  6. thrown – a string representing the throwable associated with the log record and its backtrace beginning with a newline character, if any; otherwise, an empty string.

For example, with the format you had:

%1$tc %2$s%n%4$s: %5$s%6$s%n

It would be the timestamp, source, a newline, the log level, the log message, then the backtrace

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading