Reputation: 1647
im doing a application in java and i need to do the logs, i heard about log4j, and the log api already inside, but first of all i thought about doing it inside a database like a normal statement for example:
btnPress =
{
dosomething/something with the database, when button pressed
String time = year + month + date + hour + minutes + seconds;
LogFunction("Message for the Log", time, user, screen)
}
public void LogFunction(String msg, String time String user, String screen) {
insert statement to insert into a specific table: time, user, msg, screen;
}
explaination:
a column of ordernumber(auto increase) will be the primarykey
Time: column will be different every time and the ID for searching specific log
user: column the user that generated the log
msg: column what happened and need to be logged
maybe in include something more to log
the question is:
This is Stupid, wrong, dont make sense or its a good way for doing the log?
Upvotes: 1
Views: 353
Reputation: 14164
It's important to write clear logging, to maximize the information value (and help for debugging) of what you get.
http://literatejava.com/logging/logging-the-most-effective-debugging-tool/
I recommend logging to a text file, as it's faster & cheaper.. unless you really need transaction-safe & long-term storage of your logs. Obviously it depends on requirements, but text files are normal.
Upvotes: 0
Reputation: 11396
note that log4j support logging to database as well, you dont have to write any code yourself, check out org.apache.log4j.jdbc.JDBCAppender
at the following example
Upvotes: 2