def log_get_or_delete(username=None, fetch_num=100, when=None, delete=False):
    query = Log.query(ancestor = log_key()).order(-Log.date)
    if username is not None:
        query = query.filter(Log.username == username)
    if when is not None:
        before = datetime.datetime.now() - when
        #print "before=", before
        query = query.filter(Log.date > before)
    q = query.fetch(fetch_num)
    results = []
    for i in q:
        if delete:
            tmp = { 'date': gae_datetime_JST(i.date) }
            i.key.delete()
        else:
            tmp = { 'date': gae_datetime_JST(i.date),
                    'username': i.username,
                    'what': i.what }
        results.append( tmp )
    return results