# Path: sen/constants.py
# PROJECT_NAME = "sen"
# 
# LOG_FILE_NAME = "sen.debug.log"


import os
import logging
import functools
import traceback
import time
from datetime import datetime
from docker.errors import APIError
from sen.constants import PROJECT_NAME, LOG_FILE_NAME




logger = logging.getLogger(__name__)


def _ensure_unicode(s):
    try:
        return s.decode("utf-8")
    except AttributeError:
        return s


def log_last_traceback():
    logger.error(traceback.format_exc())


def log_traceback(func):
    @functools.wraps(func)
    def wrapper(*args, **kwargs):
        logger.info("function %s is about to be started", func)
        try:
            response = func(*args, **kwargs)
        except Exception:
            log_last_traceback()
        else:
            logger.info("function %s finished", func)
            # TODO: how long it took?
            return response

# Path: sen/constants.py
# PROJECT_NAME = "sen"
# 
# LOG_FILE_NAME = "sen.debug.log"


# Path: sen/util.py
import os
import logging
import functools
import traceback
import time
from datetime import datetime
from docker.errors import APIError
from sen.constants import PROJECT_NAME, LOG_FILE_NAME





logger = logging.getLogger(__name__)


def _ensure_unicode(s):
    try:
        return s.decode("utf-8")
    except AttributeError:
        return s


def log_last_traceback():
    logger.error(traceback.format_exc())


def log_traceback(func):
    @functools.wraps(func)
    def wrapper(*args, **kwargs):
        logger.info("function %s is about to be started", func)
        try:
            response = func(*args, **kwargs)
        except Exception:
            log_last_traceback()
        else:
            logger.info("function %s finished", func)
            # TODO: how long it took?
            return response

    return wrapper