views:

126

answers:

7

I have been working on a cURL script and I am finally done, yay! Basically, right now, I am grabbing the error / success message and storing it, but how should I store it? Should I store it in a .txt file or MySQL. What is a efficient/common practice?

EDIT: I already have a MySQL database. I do not mind taking a little more time. After reading the answers, it sounds like I should store it in a database (I guess a new table). Should I store it as varchar? or should I create a SQLite database just for error logging?

A: 

If you're just storing an error/success message, then a full-blown relational database system seems a bit over the top to me.

Dominic Rodger
A: 

If you're just grabbing an error/success message, just store it to a log (text) file. Especially if the script is not running that frequently and you don't need to reference the success/error message anywhere else.

sioked
A: 

I'd go with the database. It requires no more effort than a text file (can, in fact, be significantly less), and you get lots of extra functionality. For instance, wouldn't it be nice to have a page that lets you display these errors? Perhaps with some sorting capability? A little effort up front often saves you considerable trouble down the road.

In any modern web app, you should avoid storing anything in text files. Text file repositories are nearly one-way (ie, easy to get data into, but not so much to get data back out of) unless you jump through some hoops to escape messages, provide consistent delimiters, etc. There's no good reason to use a text file, and it can, as I said, bite you later on.

David Lively
If there's a MySQL database already deployed in the project, then I agree with some qualifications. If there is NOT, then the reasons here are a lot less persuasive.
Smandoli
A: 

Unless you have grand plans for some kind of error analysis project later on, go with the text file. Fewer points of failure, somewhat less code, and fewer headaches.

Remember that if you construct an intelligent log file (text) format, you can always put it back into a database later if you want.

Tenner
+1  A: 

It entirely depends on what you plan on doing with the results. If you just want to have something to look through later if a problem occurs, a text file will probably work fine. But if you want to be able to easily create reports or search through results based on specific dates/times or something, a small SQL database would probably work. Though I'd suggest just using SQLite unless you're going to be recording a whole ton of messages a day.

Chris
+ vote for the SQLite suggestion. If MySQL is not already deployed, SQLite is certainly preferred in my opinion.
Smandoli
Should I create a SQLite database for this purpose? Just for error logs?
Doug
You are saying "create a database" as if it was something major. A sqlite "database" is very lightweight. It is even used for storing preferences in such applications as firefox, amarok and lots of others. It is used on embedded platforms too.
shylent
A: 

I would say it depends on what you want to do with the error messages. If you just want something quick and dirty that you can code with very little effort I would go with the text file.

However moving to a database does some offer a lot of benefits. You can retrieve information from it and display it in a much nicer fashion with a little bit of SQL. However I feel this does take more coding and deployment effort on your part.

So if you just want to store errors I say stay with the text file. If you want the more advanced features I would take the time to setup the database.

Justin
A: 

If you're building a spider that's going to crawl hundreds of thousands of links, and you want to track download attempts and/or the status of each URL crawled, I would create a table that maps urls to retry attempts and the date of the last attempt. I wouldn't store error messages in the database, unless the HTTP return status is more useful than a tinyint(1) representing success.

If you are crawling a modest portion of urls, and just need additional diagnostics, I'd probably stick with text files. Text error logs can be easily managed and automatically discarded by many utilities.

memnoch_proxy