logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mikael Ståldal <mikael.stal...@magine.com>
Subject Re: Allocation free timestamp formatting for GELF
Date Wed, 23 Mar 2016 16:36:27 GMT
I do:

static CharSequence formatTimestamp(final long timeMillis) {

    if (timeMillis < 1000) {
        return "0";
    } else {
        StringBuilder builder = getTimestampStringBuilder();
        builder.append(timeMillis);
        builder.insert(builder.length() - 3, '.');
        return builder;
    }
}


On Wed, Mar 23, 2016 at 5:34 PM, Remko Popma <remko.popma@gmail.com> wrote:

> In that case you may need to surround that logic with a check that the
> long value exceeds 999. Could this ever happen though?
>
> On Thu, Mar 24, 2016 at 1:18 AM, Mikael Ståldal <mikael.staldal@magine.com
> > wrote:
>
>> That seems to work. The only issue is that it doesn't handle values < 999
>> (that will be "0" now), but perhaps that's acceptable?
>>
>> See GelfLayout.java
>>
>> On Wed, Mar 23, 2016 at 4:37 PM, Remko Popma <remko.popma@gmail.com>
>> wrote:
>>
>>> How about printing the long into a StringBuilder, then insert a period
>>> at StringBuilder.length() - 3?
>>>
>>> On Thu, Mar 24, 2016 at 12:13 AM, Mikael Ståldal <
>>> mikael.staldal@magine.com> wrote:
>>>
>>>> I am trying to make GelfLayout allocation free, and got stuck at
>>>> timestamp formatting. GELF need the timestamp as number of seconds with
>>>> milliseconds as decimals.
>>>>
>>>> E.g. 1458741206653 -> "1458741206.653"
>>>>
>>>> The current implementation (in GelfLayout.java) is obviously not
>>>> allocation free:
>>>>
>>>> static CharSequence formatTimestamp(final long timeMillis) {
>>>>     return new BigDecimal(timeMillis).divide(TIME_DIVISOR).toPlainString();
>>>> }
>>>>
>>>> (see also unit test in GelfLayoutTest.java)
>>>>
>>>> Any ideas on how do fix this?
>>>>
>>>> --
>>>> [image: MagineTV]
>>>>
>>>> *Mikael Ståldal*
>>>> Senior software developer
>>>>
>>>> *Magine TV*
>>>> mikael.staldal@magine.com
>>>> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
>>>>
>>>> Privileged and/or Confidential Information may be contained in this
>>>> message. If you are not the addressee indicated in this message
>>>> (or responsible for delivery of the message to such a person), you may
>>>> not copy or deliver this message to anyone. In such case,
>>>> you should destroy this message and kindly notify the sender by reply
>>>> email.
>>>>
>>>
>>>
>>
>>
>> --
>> [image: MagineTV]
>>
>> *Mikael Ståldal*
>> Senior software developer
>>
>> *Magine TV*
>> mikael.staldal@magine.com
>> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
>>
>> Privileged and/or Confidential Information may be contained in this
>> message. If you are not the addressee indicated in this message
>> (or responsible for delivery of the message to such a person), you may
>> not copy or deliver this message to anyone. In such case,
>> you should destroy this message and kindly notify the sender by reply
>> email.
>>
>
>


-- 
[image: MagineTV]

*Mikael Ståldal*
Senior software developer

*Magine TV*
mikael.staldal@magine.com
Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com

Privileged and/or Confidential Information may be contained in this
message. If you are not the addressee indicated in this message
(or responsible for delivery of the message to such a person), you may not
copy or deliver this message to anyone. In such case,
you should destroy this message and kindly notify the sender by reply
email.

Mime
View raw message