Added 'r' (record) function to log messages to file and sessions to db

User's command, command output, return code are logged to file, sessions are
stored in the db.