How to catch all requests, even invalid ones, 400, 404 etc.

I want to save every request to the DB to do a statistical analysis later on. (ip, referer, user agent, request URI, http status code of response)

I could easily do this in index.php with plain old php, but the key here is to be able to know what HTTP status code did Yii assign to the response.

I’d thought of CController::afterAction() but that wouldn’t catch bad requests 400 and 404.

you could customize the error action in SiteController to log the errors including 404, 500, 400 etc