views:

532

answers:

3

Hello everybody. I am creating a simple Changelog lib in CodeIgniter that will basically log a message everytime someone adds, deletes, changes or publish a blog post. I will log messages in files by batches of 300. So every 301st message will go in a new file. At first I wanted to write the logs to simple .log files but then I got the idea to actually style the thing and I had to seperate each "attribute" of each message (ie: the user, the message, the type of the log, etc.). So .log files are out of the question since extracting the info would be a pain.

What is the most appropriate format for such a task? I already ruled out MySQL and XML because they are too heavy (especially considering that the log files won't exceed (about) 300 lines). I suggested YAML vs JSON vs CSV in the title, but is there yet a better alternative?

+2  A: 

I'd say it all depends on what you need/want to do with those files :

  • CSV has one advantage : it can be imported to Excel and such applications -- which might be usefull in some situations, to do reporting to a superior, for instance
  • JSON is readable in many languages, including Javascript ; but not easy to read by a human being ; and harder to modify "by hand"
  • And YAML is quite easy to read ; not hard to modify by hand ; but not sure about the availability of libraries to read it in several languages.


If you are in none of these situations :

  • must be readable
    • by a human being
    • in several programming languages
  • easy to modify
    • same notes

Then I guess all three formats will be OK ^^


Without knowing more, I would go with either CSV (for the import to Excel stuff), or JSON (for the portability reason).

Pascal MARTIN
Thank you for your answer, your reflections were very interesting. According to the context, I think JSON is the format I will choose.
Aziz Light
A: 

I guess CSV would be easier because of a couple of reasons: - count how many logs are already in the list (just count number of lines) - adding stuff to a JSON object can't be done by just appending data

Ofcourse, I you choose to create a seperate JSON object for each log item and put each on a seperate line, this isn't an issue.

julesj
A: 

I have a small question. I recently started to read a little bit about the Zend Framework. I noticed that it uses ini files for configuration files. What are the pros and cons to using ini files versus php files (confi array) or any other type of file (yaml or json?) ?

Aziz Light