Implement basisc for logging.

By default, logs are off. They can be enabled with the '-d' option. Then the log messages are printed to stdout. Error messages always go to stderr.