I have an application in whioch I want certain operation logs to be put in entities. MLore clearly, my application will provide a set of tasks, and I want these tasks to be able to write logs, later visible by users in web UI.
To my mind, the easier way to achieve that is to have tasks write their log in associated entities, stored in DB. Am I right ? and, if so, how to do that ? Create a log handler that writes in a String/Blob ?
EDIT Notice that, in some c开发者_开发知识库ases, my tasks will be run in Glassfish client, and not in server, which makes direct JDBC writing to DB irrelevant.
If these tasks are writing logs using something like Log4j, you can transparently redirect these logs to your database using the Log4j JDBC Appender (see here how). If you use another Logging engine, I suppose it has something similar to this.
Afterwards, you just have to map that table with an entity, and do regular queries through JPA (log4j would write on that table in raw SQL, but that should not be a problem for your case).
精彩评论