Such counsel fees shall not be entered as a part of such judgment unless the note, bond, mortgage, invoice, or other instrument of writing sued upon, by the terms thereof, expressly provides for the payment and allowance thereof, except in the cases of mechanics liens in which no express agreement shall be necessary in order to entitle the lien holder to his reasonable counsel fees.