logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Blake Day <bl...@chewy.com>
Subject Re: TlsSyslogFrame calculates message length incorrectly
Date Thu, 21 Jan 2016 02:18:11 GMT
I'm not sure on that, but it wouldn't fix the erroneous byte count on log messages with a multi-byte
unicode character.

> On Jan 20, 2016, at 9:04 PM, Gary Gregory <garydgregory@gmail.com> wrote:
> 
> Hm, shouldn't we be using UTF-8 instead of Charset.defaultCharset() in:
> 
>    public byte[] getBytes() {
>        final String frame = toString();
>        return frame.getBytes(Charset.defaultCharset());
>    }
> 
> ?
> 
> Gary
> 
>> On Wed, Jan 20, 2016 at 4:58 PM, Blake Day <blake@chewy.com> wrote:
>> 
>> TlsSyslogFrame appears to be miscalculating the message length.  According
>> to RFC5425, the message length must be the octet count of the SYSLOG-MSG in
>> the frame.  Though the variable below is aptly named messageLengthInBytes,
>> it is assigned the value from message.length() (where message is a String)
>> rather than the bytes.
>> 
>> See below for relevant portions of code:
>> 
>> private String message;
>> private int messageLengthInBytes;
>> 
>> private void setLengthInBytes() {
>>    messageLengthInBytes = message.length();
>> }
>> 
>> @Override
>> public String toString() {
>>    final String length = Integer.toString(messageLengthInBytes);
>>    return length + Chars.SPACE + message;
>> }
>> 
>> 
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
>> For additional commands, e-mail: log4j-user-help@logging.apache.org
> 
> 
> -- 
> E-Mail: garydgregory@gmail.com | ggregory@apache.org
> Java Persistence with Hibernate, Second Edition
> <http://www.manning.com/bauer3/>
> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
> Spring Batch in Action <http://www.manning.com/templier/>
> Blog: http://garygregory.wordpress.com
> Home: http://garygregory.com/
> Tweet! http://twitter.com/GaryGregory

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Mime
View raw message