6

I am using Wildfly 10.1 and I would really like to know what logging pattern elements i could use.

I found this documentation here: https://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/PatternLayout.html referenced by a Wildfly book.

But this can not be the whole truth, because there are more elements than mentioned there, for example the %s or %E Elements.

I also found this https://logging.apache.org/log4j/2.x/manual/layouts.html but that cant be the truth eiter, because the mentioned %throwable{short.className} does not work.

Also the Wildfly Documentation at https://docs.jboss.org/author/display/WFLY10/Handlers#Handlers-formatter does not say a word about what pattern elements are available.

I try to create a logging pattern which will generate only one line per exception (no stack trace) but still contain the Message of the exception and the Class, Method and Line Number.

Thomas
  • 620
  • 7
  • 19
  • 1
    Unfortunately at this point there is no documentation for it. Though it's definitely on the TODO list. There is also not a default way to only log the `Throwable.getMessage()`. You'd have to write a custom-formatter. – James R. Perkins Dec 13 '17 at 00:41
  • 1
    Thank you for your answer, so I know I can stop looking for it. But while we are at it, could you point me in the direction to find the source that parses the pattern String? Maybe I can figure it out by reading the source. – Thomas Dec 14 '17 at 08:21
  • 3
    Sure thing. The current upstream is https://github.com/jboss-logging/jboss-logmanager/blob/master/src/main/java/org/jboss/logmanager/formatters/FormatStringParser.java#L84-L197 – James R. Perkins Dec 14 '17 at 17:08
  • Brilliant! Thank you so much! – Thomas Dec 14 '17 at 19:15
  • 2
    So, this almost looks like logback. Is there a reason wildfly isn't just depending on the logging facility? – end-user Oct 26 '18 at 18:48

1 Answers1

2

Now there is a document for logging formatters. Wildfly Logging Formatters

You could use %l for location information, but there is no pattern for exception message without stacktrace.

Here is the relevant parts from the document;

%l: The location information. This includes the callers class name, method name, file name and line number.

%m: The formatted message including any stack traces.

%s: The simple formatted message. This will not include the stack trace if a cause was logged.

%e: Prints the full stack trace.

%e{0}: Prints the stack trace ignoring any suppressed messages.

%e{1}: Prints the stack trace with a maximum of one suppressed message.

Community
  • 1
  • 1
mkayman
  • 100
  • 1
  • 2
  • 11