def configure(config):
    """When using Lino's default method, the :setting:`LOGGING` setting in
your :xfile:`settings.py` must be a dictionary containing the
parameters you want to set.  Available parameters are:

:param logfile:  the full path of the lino `system.log` file.
                 If absent or `None`, there will be no `system.log` file.
                 
:param level:    the overall verbosity level for both console and logfile.
:param mode:     the opening mode for the logfile
:param encoding: the encoding for the logfile
:param tty:      whether to install a default logger to the terminal

:param logger_names:  A list or tuple of names of loggers to configure.
                      If this is a string, Lino converts it to a list 
                      (expecting it to be a space-separated list of names).
                      Default value is 'lino'.
                 
If there is a logfile, then console messages will never be more
verbose than INFO because too many messages on the screen are
disturbing, and if the level is DEBUG you will better analyze them in
the logfile.

Automatically adds an AdminEmailHandler with level ERROR to all
specified loggers *and* to the 'django' logger (even if 'django' is
not specified in `loggers`).  Because that's rather necessary on a
production server with :setting:`DEBUG` False.

    """

    if getattr(logging, "set_up_done", False):
        msg = "Not changing the existing logging configuration."
        # raise Exception(msg)
        logging.info(msg)
        return
    logging.set_up_done = True

    # if len(logging.getLogger().handlers) != 0:
    #     msg = "Not changing the existing logging configuration."
    #     # raise Exception(msg)
    #     logging.info(msg)
    #     return

    #~ logger_names = config.get('logger_names','djangosite lino')
    logger_names = config.get('logger_names', None)
    #~ print 20130826, logger_names
    if not logger_names:
        #~ print 20130418, __file__, 'no logger names'
        return  # Django 1.5 calls this function twice (#20229)
        #~ raise Exception("Missing keyword argument `logger_names` in %s." % config)

    djangoLogger = logging.getLogger('django')
    linoLogger = logging.getLogger('lino')

    from django.utils.log import AdminEmailHandler

    # print 20150623, config
    # encoding = config.get('encoding', 'UTF-8')
    logfile = config.get('filename', None)
    rotate = config.get('rotate', True)
    tty = config.get('tty', True)

    level = getattr(logging, config.get('level', 'notset').upper())
    if isinstance(logger_names, basestring):
        logger_names = logger_names.split()
    #~ print "20130418 configure loggers", logger_names, config
    loggers = [logging.getLogger(n) for n in logger_names]

    # for l in loggers:
    #     if len(l.handlers) != 0:
    #         msg = "Not configuring logging because already configured."
    #         l.info(msg)
    #         return

    for l in loggers:
        l.setLevel(level)

    aeh = AdminEmailHandler(include_html=True)
    aeh.setLevel(logging.ERROR)
    for l in loggers:
        l.addHandler(aeh)
    if 'django' not in logger_names:
        djangoLogger.addHandler(aeh)

    if tty:
        try:
            if sys.stdout.isatty():
                h = logging.StreamHandler()
                if logfile is not None:
                    h.setLevel(logging.INFO)
                #~ print "20130826 tty", h, loggers
                fmt = logging.Formatter(fmt='%(levelname)s %(message)s')
                h.setFormatter(fmt)
                for l in loggers:
                    l.addHandler(h)
        except IOError:
            # happens under mod_wsgi
            linoLogger.info("mod_wsgi mode (no sys.stdout)")

    if logfile is not None:
        try:
            kw = {}
            for k in ('mode', 'encoding'):
                if k in config:
                    kw[k] = config[k]
            h = file_handler(logfile, rotate, **kw)
            #~ h.setLevel(level)
            for l in loggers:
                l.addHandler(h)

        except __HOLE__ as e:
            raise Exception("Failed to create log file %s : %s" % (logfile, e))
            # linoLogger.exception("Failed to create log file %s : %s", logfile, e)
            # linoLogger.exception(e)


    #~ linoLogger.info("20120408 linoLogger.handlers: %s", linoLogger.handlers)
dataset/ETHPy150Open lsaffre/lino/lino/utils/log.py/configure