Github user jburwell commented on the pull request:

    https://github.com/apache/cloudstack/pull/1331#issuecomment-212596332
  
    @rafaelweingartner the garbage collection issue is not the 
allocation/deallocation, but the reachability calculation that the garbage 
collector must perform for every instance member (i.e. determining whether or 
not that instance needs to be collected).  Since it, ultimately, the logger is 
a singleton, this reachability check is completely unnecessary.  In contrast, 
the garbage collector skips this check for ``static final`` members as it is 
guaranteed to be reachable for the lifetime of the JVM.  While the overhead of 
this check is relatively small, making logger (or any other constant values) 
instance members on classes whose instances  are rapidly allocated and 
deallocated accrues quickly.
    
    @syed Done properly, the appender approach can be made reusable for other 
test cases to verify logging behavior.  I built a [custom 
appender](https://gist.github.com/jburwell/98b6d94c57f409b5b778ffee6a8a12b1) 
that allows monitoring of a logger for one or more patterns and assert that 
logging occurred as expected.   The following is an example of how to use it in 
this test case:
    
    ```
    public class NfsSecondaryStorageResourceTest {
    
        private TestAppender testAppender;
    
       @Before
       public void setup() {
           testAppender = new 
TestAppenderBuilder().addExpectedPattern(Level.DEBUG, "Failed to clean up 
staging area:\*+").build();
           Logger logger = Logger.getLogger(NfsSecondaryStorageResource.class);
           TestAppender.safeAddAppender(logger, testAppender);
       }
    
       @Test
       public void testSwiftWriteMetadataFile() throws Exception {
           // test operations and asserts
           testAppender.assertMessagesLogged();
       }
    ```
    
    The class likely needs a little work, and definitely, some testing.  I put 
it together quickly to demonstrate  a reusable approach to testing logging.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to