Initial implementation of output logging

Not very good or efficient yet.