Any person who is duly served with a writ of habeas corpus commanding him to produce the body of any other person in his custody, who shall fail to produce the body of the person before the judge, according to the command of the writ, shall forfeit and pay to the party not so produced the sum of One Thousand Dollars ($1,000.00), to be recovered before any court having jurisdiction, the right to recover which shall not cease by the death of either party. The judge before whom the writ was made returnable may also punish the person failing to obey the command thereof or to perform the duties prescribed, or to obey such order as the judge may make, as for a contempt, and compel obedience by process of attachment or otherwise. Any officer from whom the custody of any person is taken by writ of habeas corpus who shall fail to return the cause of commitment of any prisoner or other person as prescribed, may be punished in like manner.