Welcome Guest, Not a member yet? Register   Sign In
write_log() does not call write_file(), why not?

I see that write_log() does not call write_file(), but instead re-implements the same sort of php file manipulation code. Wouldn't it be good to have write_log() call write_file() in an eat-your-own-dog-food sorta way?

I use write_log() for error, debug, and info that is designed for the developer to use. I also want to log some other info for historical purposes to a different file; so I started looking through CI docs and source to see what I could find for this. I found write_file() and seems to fit my needs. I'll wrap it in a library class to encapsulate the file naming convention and other details (similar to write_log). While I was looking though the source for my solution I found that write_log() and write_file() implement similar php file manipulation code and I thought, DRY (don't repeat yourself).

CodeIgniter_1.5.4\system\libraries\Log.php -- write_log()
CodeIgniter_1.5.4\system\helpers\file_helper.php -- write_file()
Note, the global log_message() calls write_log()

Thanks for CI, I love it! ~ Mark

thanks for the nice observation mmaruska - and on your first post too! welcome to CI. maybe we should call it "eating your own DRY dog food"!

a reason:
it's because write_file() is in a "helper" and that would mean loading the "helper" to access the function.

another reason:
the log class was probably written first and then someone thought "we need a way to standardize filewriting" and created that helper. the helper remains because it is simple to use and understand and easy to get to. the log filewriting code remains because it is just a few lines of extra weight and means one less function call.

a thought (your thought):
the filewriting lines of write_log() method and the write_file() functions could be refactored into one function that resides in the Common.php file.

the helper has a bunch of other functions to deal with files so it is a tidy and complete (modular, as it were) little pack.

the Dereks are hard at work getting to v1.6 so if you think this is a point worth stressing, now is the time to do it.

looking forward to seeing more good stuff from you!

so, i found this in the changelog today:

"Added is_really_writable() to Common.php to provide a cross-platform reliable method of testing file/folder writability."

so, the devs *will* move functions into Common.php but more readily for cross-platform usage. it makes sense to have write_file() be moved into common.php also (for the reasons why is_really_writeable() was moved in there). then, everyone will have a standard way of writing files just like they have a standard (portable) way of checking file_writeable staus and active record for using dbs, etc...

Theme © iAndrew 2016 - Forum software by © MyBB