def fmt_val(val, shorten=True):
    """Format a value for inclusion in an 
    informative text string.
    """
    val = repr(val)
    max = 50
    if shorten:
        if len(val) > max:
            close = val[-1]
            val = val[0:max - 4] + '...'
            if close in ('>', "'", '"', ']', '}', ')'):
                val = val + close
    return val
