Log customized stirng before & after running func.
323229
def log_before_after(name: str, desc: str):
    """"""

    def func_decorator(f):
        """Wrapper stub."""

        @ft.wraps(f)
        def wrapper(*args, **kwargs):
            """Wrapper stub."""
            LOG.info("\n%s - %s", name, desc)
            res = f(*args, **kwargs)
            if StepResult.ERROR not in res:
                LOG.info("%s - OK\n", name)
            else:
                LOG.error("%s - ERROR\n", name)
            return res

        return wrapper

    return func_decorator
1334096
def with_log(func):
    
    @functools.wraps(func)
    def wrapper(*args, **kwargs):
        """Inject `log` argument into wrapped function.

        :param list args: Pass through all positional arguments.
        :param dict kwargs: Pass through all keyword arguments.
        """
        decorator_logger = logging.getLogger('@with_log')
        decorator_logger.debug('Entering %s() function call.', func.__name__)
        log = kwargs.get('log', logging.getLogger(func.__name__))
        try:
            ret = func(log=log, *args, **kwargs)
        finally:
            decorator_logger.debug('Leaving %s() function call.', func.__name__)
        return ret
    return wrapper
194208
def decorate(self, fun):
        """"""
        @wraps(fun)
        def _decorated(*args, **kwargs):
            # Push the config, run the function and pop it afterwards.
            self.push_config()
            try:
                return fun(*args, **kwargs)
            finally:
                self.pop_config()
        return _decorated
231889
def apply_log(a: tuple, func: Callable[[Any], Tuple[Any, Log]]) -> Tuple[Any, Log]:
        
        value, log = a
        new, entry = func(value)
        return new, log + entry
971986
def _decorate_fun(self, fun):
        """"""

        msg = "Function %s is deprecated" % fun.__name__
        if self.extra:
            msg += "; %s" % self.extra

        def wrapped(*args, **kwargs):
            warnings.warn(msg, category=DeprecationWarning)
            return fun(*args, **kwargs)

        wrapped.__name__ = fun.__name__
        wrapped.__dict__ = fun.__dict__
        wrapped.__doc__ = self._update_doc(fun.__doc__)

        return wrapped
933152
def _log(self, level, msg, args, exc_info=None, extra=None):
        """"""
        if exc_info and not isinstance(exc_info, tuple):
            exc_info = sys.exc_info()

        self.append(HistoryRecord(level, "unknown filename", 0, msg, args, exc_info, func="unknown func"))
250689
function log(message, level) {
    var prefix = "[" + colors.cyan("gulp-tslint") + "]";
    if (level === "error") {
        fancyLog(prefix, colors.red("error"), message);
    }
    else {
        fancyLog(prefix, message);
    }
}
371211
def log_time(func: Callable[..., Any]) -> Callable[..., Any]:
    

    def wrapper(*args, **kwargs):
        start_time = time.time()
        log.info("%s starting...", func.__name__.title())
        ret = func(*args, **kwargs)
        log.info(
            "%s finished (%s)",
            func.__name__.title(),
            datetime.timedelta(seconds=int(time.time() - start_time)),
        )
        return ret

    return wrapper
1152426
def timed_do_fn(f):
    """"""
    def wrap(callable, *args, **kwargs):
        global _debug_id

        # get a description of the function that called us
        st = traceback.extract_stack(limit=2)
        file, line, name, _ = st[0]

        # and its locals
        frame = inspect.currentframe()
        locals = frame.f_locals

        # invent a unique ID for the description
        id, _debug_id = _debug_id, _debug_id + 1

        descr = "%s-%08x" % (name, id)

        start_time = time.time()
        log.msg("%s - before ('%s' line %d)" % (descr, file, line))
        for name in locals:
            if name in ('self', 'thd'):
                continue
            log.msg("%s -   %s = %r" % (descr, name, locals[name]))

        # wrap the callable to log the begin and end of the actual thread
        # function
        def callable_wrap(*args, **kargs):
            log.msg("%s - thd start" % (descr,))
            try:
                return callable(*args, **kwargs)
            finally:
                log.msg("%s - thd end" % (descr,))
        d = f(callable_wrap, *args, **kwargs)

        @d.addBoth
        def after(x):
            end_time = time.time()
            elapsed = (end_time - start_time) * 1000
            log.msg("%s - after (%0.2f ms elapsed)" % (descr, elapsed))
            return x
        return d
    wrap.__name__ = f.__name__
    wrap.__doc__ = f.__doc__
    return wrap
260084
def log_with_message(message):
    

    def decorator(func):
        @wraps(func)
        def wrapper(*args, **kwargs):
            print('decorator log_with_message is running, %s' % message)
            ret = func(*args, **kwargs)
            return ret

        return wrapper

    return decorator
443472
def during(f):
    """"""
    def decorator(g):
        @wraps(g)
        def h(*args, **kargs):
            tf = Thread(target=f, args=args, kwargs=kargs)
            tf.start()
            r = g(*args, **kargs)
            tf.join()
            return r
        return h
    return decorator
1363624
def once(func):
    """"""
    lock = threading.Lock()

    def new_func(*args, **kwargs):
        if new_func.called:
            return
        with lock:
            if new_func.called:
                return
            rv = func(*args, **kwargs)
            new_func.called = True
            return rv

    new_func = update_wrapper(new_func, func)
    new_func.called = False
    return new_func
398245
def timeit (func, log, limit):
    """"""

    def newfunc (*args, **kwargs):
        """Execute function and print execution time."""
        t = time.time()
        res = func(*args, **kwargs)
        duration = time.time() - t
        if duration > limit:
            print(func.__name__, "took %0.2f seconds" % duration, file=log)
            print(args, file=log)
            print(kwargs, file=log)
        return res
    return update_func_meta(newfunc, func)
1181154
def log_wrap(origfunc):
    
    def orig_func_wraper(msg, *args):
        # Take the callers name and snap it in two, result is log
        # level, e.g.: log_debug is DEBUG level.
        log_level = origfunc.__name__.split("_")[1]

        import Log
        if getattr(Log, "LOG_%s" % log_level.upper()) <= \
                Log.LOG_LEVEL_CURRENT:
            # flatten and stringify the positional params so we don't
            # tuple() a tuple or an array and end up with
            # weirdness.
            a = map(str, juicer.utils.flatten(args))
            print_log_msg(log_level, str(msg) % tuple(a))
    return orig_func_wraper
771649
def _record_call(func):
    

    @wraps(func)
    def wrapper(*args, **kwargs):
        global global_error_context

        # log a call as about to take place
        if global_error_context is not None:
            key = CallLogKey(name=func.__name__,
                             args=[serialize_object_for_logging(arg) for arg in args],
                             kwargs={k: serialize_object_for_logging(v) for k, v in kwargs.items()})

            pre_entry = CallLogValue(timestamp_in=datetime.utcnow(),
                                     timestamp_out=None,
                                     return_value=None)
            global_error_context.log[key] = pre_entry

        val = func(*args, **kwargs)

        # poke the return value of that call in
        if global_error_context is not None:
            post_entry = CallLogValue(timestamp_in=pre_entry.timestamp_in,
                                      timestamp_out=datetime.utcnow(),
                                      return_value=serialize_object_for_logging(val))
            global_error_context.log[key] = post_entry

        return val

    return wrapper
1267077
def decorate(func, caller, extras=()):
    
    evaldict = dict(_call_=caller, _func_=func)
    es = ''
    for i, extra in enumerate(extras):
        ex = '_e%d_' % i
        evaldict[ex] = extra
        es += ex + ', '
    fun = FunctionMaker.create(
        func, "return _call_(_func_, %s%%(shortsignature)s)" % es,
        evaldict, __wrapped__=func)
    if hasattr(func, '__qualname__'):
        fun.__qualname__ = func.__qualname__
    return fun
86935
def timing(func):
    """"""
    @functools.wraps(func)
    def wrap(*args, **kw):
        t0 = time()
        result = func(*args, **kw)
        t1 = time()
        print('func:%r args:[%r, %r] took: %2.4f sec' %
              (func.__name__, args, kw, t1 - t0))
        return result
    return wrap