import math


def mag(obj, base=10):
    """Return the magnitude of the object (or its length), or -1 if size is 0."""
    try:
        size = len(obj)
    except TypeError:
        size = obj

    try:
        m = int(math.log10(size) if base == 10 else math.log(size, base))
    except:
        m = -1

    return m