Jan 252013
 

I was asked to find a solution to write customized Apache log entry (in Apache access log, not error log), other requirements include easy to use, which implicitly means “PHP friendly”, and flexible, which means “free format” and “may or may not have the value”.

Seriously, the first thing jumped into my mind was an Apache module (let’s hack mod_log!) or a PHP extension, but later on I found that … I don’t want to maintain another orphan project especially it will be orphan since nobody want to touch it after it’s up and running (I have one already, which does some cookie stuffs). So I move on to Google …

Then I found apache_note(), plus mod_log_config (search for %{Foobar}n), all that I need to do is tell PHP guys to call this function, and tell ops guys to setup Apache log properly, we are all set.

It’s good to see apache_note can change the note as many times as you want, whenever the request is finished on server side, the final data will be written to log.