Using java and made a small test server to log incoming user connections.
Adding the MongoDb as Databas and the log4j mongo appender log4j.properties
text file configured to save the Log class to Mongo.
Everything is nice.
I can now search among all Log Collections and trace a particular user based on the “message”
I immediately thought that it could be cool to log each individual user event to respective UserData Collection Document.
Users are also stored in the mongo as a UserData class Collection.
Why i think about this is because its hard to trace user log activity if you have multiple threads all writing to the same Log Collection.
When a user loggin i wanted to attach/append the user to a new Logger and let this logger live as long as user is on the server.
Is this what the MongoDbPatternLayoutAppender is all about?
The documentations and tutorials about this is sparse maybe someone can explain?
Am i on the right track here?
What’s best to do?
This answer is not related to MongoDB in particular…
If you’re willing to try LogBack you could use a SiftingAppender that does exactly what you’re looking for!
For logging best practices (slf4j, log4j, LogBack, etc) you can take a look at this document here.