use layout to format message if it is non-null