Implement logging levels

Implement the following logging levels:

`DEBUG`, `INFO`, `WARNING`, `ERROR` and `FATAL`

`INFO` outputs to stdout; all other levels output to stderr.

The default log level output is ERROR and above; this can be tweaked by
providing an integer value to the `-loglevel` flag. A value of `0`
corresponds to `DEBUG` and `4` corresponds to `FATAL` (values 0-4 are
valid).

Note that I have only changed the main package to use these levels so
that the other packages remain portable.

Also, move much as possible of the package initialisation to the
`init()` function.