Home Ask Login Register

Developers Planet

Your answer is one click away!

sgjklseghlesg February 2016

Is it good or bad to store log messages in a database table, rather than a file?

I'm talking about human-readable text logging, like error messages from a web application.

Do people commonly store these in a database? Are there any advantages to using a database table instead of a file? Or if not, why is it specifically a bad idea?


Mukesh Keshu February 2016

I hope this link gives you a better idea - What's more efficient - storing logs in sql database or files?

Log to db instead if you need other people needs to read logs in a web interface or if you need the ability to search through logs

Arve Systad February 2016



  • Way easier to search through the logs
    • Clever queries, grouping and limiting by for example dates
    • Retrieving log messages of a specific kind, log level or containing certain patterns
    • Filtering away unwanted noise when looking for specific things
  • Easier to manage in a good way if you're creating some kind of user interface

Some disadvantages:

  • Pollutes your database with stuff that might not be very useful, depending on your application
  • Can aid in far quicker database growth, which might be annoying in certain scenarios
  • You need access to the database (which might require paper work or simply takes time), or write a UI on top

Text files

Major advantages

  • Very easy, light weight, simple to implement
  • Easy to clean away when not needed anymore; no longer wasting disk space


  • Hard to browse and query (depends on your logging statements, file structures etc)

There's nothing inherently right or wrong with logging to a database versus logging to a file; it all depends on your needs. Think through your needs, then decide. Logging to a database is very convenient when debugging, but it might require more of you, your team or your application in the long run.

Post Status

Asked in February 2016
Viewed 2,561 times
Voted 11
Answered 2 times


Leave an answer

Quote of the day: live life