I’m building a jsf Web App in Eclipse, and I’ve given the app a logger. I’m using the log4j API to log into a db in my server. to acomplish this I followed this tutorial and everything works fine.
The “message” put into the logger has the following format: ((userName)) << clientNumber>> – actionLogged
Problem
since this is going into a db and I’m going to have to give a report on the logged information, I need to be able to filter through the userName, the clientNumber and the Actions but I can’t really do that if I have a super long String with all the info in the “message” column, so my first thoughts were these:
Possible Solution #1
Is there a way to parse the message in the log4j.properties file before I insert it into the db so that I may insert the parsed strings into the corresponding columns in the table?
Possible Solution #2
Is there a way to cheat the insert statement in the log4j.properties so that I can change the format and add commas, quotes to the message itself so that the API inserts into the rest of the columns ( i.e. *userName’, ‘clientNumber’, ‘actionLogged )
Possible Solution #3
When I do the insert into the table in my db, I use a trigger to parse the message and insert the values into a second table (or the same one) with the correct userName, clientNumber and Action Columns.
Please give this some thought and let me know what you think is the best approach. or if you want to suggest a better solution, please go ahead, Thanks!!!
~Myy
What I recommend anybody using the log4J is that if you want the fast and easy way to do it, is to create a trigger before the insert in the DB. This way you can parse the message coming in, since you can’t really parse it with log4J. So I added 3 more columns to my Table, userName, ClientId and Action. then I parsed the log4j "message" and populated the fields in the insert with it. Hope this helps somebody someday having the same trouble I did.