Open pastorcmentarny opened 10 years ago
There is a unit test that provides an example in TestMongoDbPatternLayout.java in the method testHostInfoPatternLayout(). The method it calls that you will be interested in is getHostInfoPatternLayoutProperties().
That method programatically sets the pattern with:
props.put( "log4j.appender.MongoDBPatternLayout.layout.ConversionPattern", "{\"timestamp\":\"%d{yyyy-MM-dd'T'HH:mm:ss'Z'}\",\"level\":\"%p\",\"array\":[\"%c{1}\",\"%m\"],\"host\":{\"name\":\"%H\", \"process\":\"%V\", \"ip_address\":\"%I\"}}");
The conversion characters you are probably interested in are %H, %V and %I. These custom conversion characters are implemented in HostInfoPatternParser.java.
Please let me know if I understood your question correctly.
Thank you very much. You understand my question correctly. I was interesting in %H, %V and %I. Unfortunately ,they do not work,when i use them in log4j,properties as log4j do not recognize them: log4j:ERROR Unexpected char [I] at position 198 in conversion patterrn.
but i will try to solve this problem and let you know. One more time thank you very much
First! Thank you very much for amazing log4mongo appender. It is masterpiece of development.
I have a question How I can add host (ip and etc) data to MongoDbPatternLayoutAppender while I am using ConversionPattern ? as by default these information is added, but I don’t know how to add these data when I am using ConversionPattern as log4j itself do not obtain this data is any Conversion Character used? I mean how to add "host" : { "process" : "3420@ CHEESE1" , "name" : "CHEESE1" , "ip" : "4.4.4.4"}} from default appender to log4j.appender.MongoDB.layout.ConversionPattern={"timestamp":"%d{yyyy-MM-dd'T'HH:mm:ss'Z'}","level":"%p","class":"%c{1}","message":"%m ?????
Thank you for answer in advance!