First attempt at sql logging.

The log generator is currently completly bork, will be implemented in a
subsequent commit.