"""
This module provides easier retrieving of loggers.
Logger name can be autoprefixed so you can customize logging output
with logging configuration.
"""
import logging
try:
    from django.conf import settings
except ImportError:
    print("Can't import django settings.")
    settings = None


def get_logger(logger_name, autoprefix=True):
    """
    Returns a logger with given name.
    If autoprefix is True, then logger name will be prefixed
    with SITE_NAME from your django settings.
    :param logger_name: Name of the logger.
    :type logger_name: str
    :param autoprefix: Enables autoprefixing (default True)
    :type autoprefix: bool
    :returns: Logger with given name.
    """
    if autoprefix and settings and hasattr(settings, 'SITE_NAME'):
        logger_name = "{0}.{1}".format(settings.SITE_NAME, logger_name)
    return logging.getLogger(logger_name)
