Can I log the searches that are returning 404 in the DB?

Can I log the searches that are returning 404 in the DB?