JC: refactoring log controller. Moved all selection into sql_code for log index.