Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to add host information to ConversionPattern while i am using MongoDbPatternLayoutAppender ? #18

Open
pastorcmentarny opened this issue Nov 28, 2013 · 2 comments
Assignees

Comments

@pastorcmentarny
Copy link

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!

@RobertStewart
Copy link
Collaborator

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.

@ghost ghost assigned RobertStewart Nov 30, 2013
@pastorcmentarny
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants