State machine with logging