tags:

views:

59

answers:

4

Hi there!

Right now I'm logging some info of the user in my web app in a log file to observe the usage & interest for some services, but I'm interested in checking that info in a readeable way, so I'm questioning if maybe I shall save that info in a database and then retrieve it to show it in tables or whatever.

It's better to log in the database for my purposes? Or logging like now I could select/order the info of the log easily?

A: 

If you need to order that data in many ways, the database is the obvious choice.

If you instead just need the data in order or creation, then file is an option.

Lo'oris
Yeah, that's what I don't want to do, show the info like it's written in the logs.
Fungsten
A: 

This depends entirely on what kind of info you're logging and how often the logging occurs. Can you give us more specifics?

If this information needs to be relational, then the database is your obvious choice.

If it's not and logging occurs on every page request and it's not a low traffic site, you'll get better performance by appending to a file and importing for later analysis.

webbiedave
The info is basically the user, time and the event/service, and it's not happening in every page, so it wouldn't be a problem to run queries for storing the data
Fungsten
A: 

You might consider using SQLite to log this sort of thing. It gives you the power and convenience of a relational DB, without adding additional overhead. SQLite queries are almost as inexpensive as regular file I/O.

Given the type of information you are logging, I think you'd just frustrate yourself writing it line by line in a plain file. You'll want to run queries, so the DB is (as others have said) the obvious choice.

Tim Post
+1  A: 

Advantages of log file:

  • Local
  • Don't need anything special to read it (just a text editor)

Advantages of database storage:

  • You can filter more easily (give me all WARN level entries that occured last tuesday)
  • You can format the output however you want, because that is handled by the front end. Display it in tables, lists, have ajax search, nice graphs, etc.
  • It's scalable! If you have 3 web servers, you can have them all writing to the same log file.

Downside of database storage:

  • If you're doing a lot of logging you can peg your database by having each request logging multiple times.
ryeguy