import logging
import time


def timeit(f):
    """
    Timing decorator for functions. Just add @timeit to start and function
    will be timed. It will write starting and ending times

    Parameters
    ----------
    f : function
        decorator takes the function as parameter
    Returns
    -------
    mixed
        return value of function itself
    Raises
    ------
    Error
        when any error thrown by called function does not catch it
    """

    def wrapper(*args, **kwargs):
        logger = logging.getLogger("main")
        logging.info("...")
        logging.basicConfig()
        logger.info(f"Started: {f.__qualname__}.")
        t = time.time()
        res = f(*args, **kwargs)
        logger.info(f"Finished: {f.__qualname__} elapsed: {time.time() - t:.2f}s.")
        logging.info("...")
        return res

    return wrapper