Fixed bugs in logdie, logwarn, template expansion

Fixed bugs in logdie and logwarn to make output format consistent
with the "real" counterparts.

Fixed some bugs regarding expansion of templates.

Bug spotting and fixing thanks to Felix Li.