First attempt at sql logging.

The log generator is currently completly bork, will be implemented in a
subsequent commit.
Forgot to add the config.example changes

Derp!
some sql fixes
make it not crash
first stab at log-gen
more time fixes
more log fixes
more log fixes + fix #238
misc fixes
implement day turnover + more fixes
make db more generic
fix reverse
make !s work