Correct way of using HashMap for logging in log4j2 -
Correct way of using HashMap for logging in log4j2 -
i want generate key value pairs in log4j2 dont want define new name hashmap create everytime. below code work on scenarios or there chance gc cleanup before hashmap objects eventhough passed reference log4j class before logs map asynchronously?
map<string,string> mymap = new hashmap<string,string>(); mymap.put("card_token", "abcdefg"); mymap.put("action", "start of sample app"); mymap.put("desc", "start of sample splunk app"); logger.error(new mapmessage(mymap)); for(int i=0;i<4;i++) { mymap = new hashmap<string,string>(); mymap.put("action", "inside loop"); mymap.put("desc", "inside loop of sample app"); mymap.put("loop_count", string.valueof(i)); logger.error(new mapmessage(mymap)); } mymap = new hashmap<string,string>(); mymap.put("action", "end of sample app"); mymap.put("desc", "end of sample splunk app"); logger.error(new mapmessage(mymap));
no, don't worry, gc won't clean still has references it. hashmap won't gc'ed until after logged.
hashmap log4j2
Comments
Post a Comment