Every warrant of commitment issued by a court or officer for contempt arising from disobedience to a subpoena, or refusal to be sworn, or to answer as a witness, or to subscribe an affidavit or deposition when required, shall specify therein the cause of the commitment; and if it is for refusing to answer, such question shall be stated in the warrant.