Add logging table

* Adds a database table to store log entries in the database
* Creates the mathlog table if the mathdebug mode is enabled
* Replaces dirname( __FILE__ ) -> __DIR__

Change-Id: I7935f33e04a1c9d7d4f1dbbc600e840f07c19dad