Skip to content

Commit

Permalink
Merge pull request #1 from Kami/use_message_if_short_message_is_not_a…
Browse files Browse the repository at this point in the history
…vailable

Append stack trace to short_message if extractStacktrace is true and shortMessage is empty
  • Loading branch information
Kami committed Mar 8, 2012
2 parents b69b11c + 85ce4ce commit a8ed9a9
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions src/main/java/org/graylog2/logging/GelfHandler.java
Expand Up @@ -155,16 +155,8 @@ public void close()
private GelfMessage makeMessage( final LogRecord record )
{
String message = record.getMessage();

final String shortMessage;
if ( message.length() > MAX_SHORT_MESSAGE_LENGTH )
{
shortMessage = message.substring( 0, MAX_SHORT_MESSAGE_LENGTH - 1 );
}
else
{
shortMessage = message;
}
String shortMessage = new String(message);
String stackTrace;

if ( extractStacktrace )
{
Expand All @@ -173,10 +165,20 @@ private GelfMessage makeMessage( final LogRecord record )
{
final StringWriter sw = new StringWriter();
thrown.printStackTrace( new PrintWriter( sw ) );
message += "\n\r" + sw.toString();
stackTrace = "\n\r" + sw.toString();
message += stackTrace;

if ( shortMessage.length() == 0 ) {
shortMessage += stackTrace;
}
}
}

if ( shortMessage.length() > MAX_SHORT_MESSAGE_LENGTH )
{
shortMessage = shortMessage.substring( 0, MAX_SHORT_MESSAGE_LENGTH - 1 );
}

final GelfMessage gelfMessage =
new GelfMessage( shortMessage,
message,
Expand Down

0 comments on commit a8ed9a9

Please sign in to comment.