[ 
https://issues.apache.org/jira/browse/LOG4J2-3017?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17282959#comment-17282959
 ] 

Volkan Yazici commented on LOG4J2-3017:
---------------------------------------

I think I have managed to prove that this issue has nothing to do with Log4j, 
but the byte code instrumentation performed by Groovy:
{code:groovy}
package com.vlkan.sandbox.groovy

import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test

class Log4jGroovyTest {

    private static final boolean THREAD_DUMP_ENABLED = true

    private static final class Item {

        private int toStringInvocationCount = 0;

        @Override
        synchronized String toString() {
            if (THREAD_DUMP_ENABLED) {
                Thread.dumpStack()
                System.err.println()
            }
            toStringInvocationCount++
            return "item"
        }

    }

    // succeeds
    @Test
    void test_inline_String() {
        Item item = new Item()
        format("number: " + item)
        Assertions.assertEquals(1, item.toStringInvocationCount)
    }

    // succeeds
    @Test
    void test_GString_assigned_to_String() {
        Item item = new Item()
        String message = "number: ${item}"
        format(message)
        Assertions.assertEquals(1, item.toStringInvocationCount)
    }

    // fails
    @Test
    void test_GString_assigned_to_GString() {
        Item item = new Item()
        GString message = "number: ${item}"
        format(message)
        Assertions.assertEquals(1, item.toStringInvocationCount)
    }

    // fails
    @Test
    void test_inline_GString() {
        Item item = new Item()
        format("number: ${item}")
        Assertions.assertEquals(1, item.toStringInvocationCount)
    }

    private static void format(CharSequence message) {
        StringBuilder builder = new StringBuilder()
        builder.append(message)
    }

}
{code}

I am closing the ticket. [~cliviu], I think it is wise to move the discussion 
to the Groovy project issue tracker.

> Groovy logging of GString with $ notation is very slow
> ------------------------------------------------------
>
>                 Key: LOG4J2-3017
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-3017
>             Project: Log4j 2
>          Issue Type: Question
>            Reporter: Liviu Carausu
>            Priority: Major
>         Attachments: SomeClass.groovy, TestLogging.groovy
>
>
>  
> Logging of GString is very slow.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to