#!/usr/bin/env python

import os
from .config import Config
from logging.handlers import TimedRotatingFileHandler

import logging

def get_logger(appname):
    config = Config()
    log_config         = config.get("log")
    log_level          = log_config.get("level")
    log_path_templates = log_config.get("paths")
    log_path           = get_log_path(appname, log_path_templates)

    trfh = TimedRotatingFileHandler(log_path, when='D', interval=1, backupCount=5, encoding='utf-8')
    logger = logging.getLogger(appname)
    logger.addHandler(trfh)
    logger.error("trfh")
    logger.setLevel(logging.DEBUG)
    return logger

def get_log_path(appname, log_path_templates):
    for log_path_template in log_path_templates:
        try:
            log_path = log_path_template.format(appname=appname)
            try:
                os.makedirs(os.path.dirname(log_path), 0755)
            except OSError, e:
                if e.errno != 17:
                    # We can ignore a 'directory exists' error
                    raise

            fh = open(log_path, 'a')
            fh.write("-- starting up --")
            fh.close()
            return log_path
        except Exception, e:
            pass

    raise Exception("Failed to find a writeable log path in config")

@@ -211,15 +211,24 @@
 get(
+appname, 
 %22log%22)%0A
-
     
@@ -389,16 +389,136 @@
 lates)%0A%0A
+    formatter = logging.Formatter('%25(asctime)s: %25(levelname)s : %25(message)s    %5B%25(process)d:%25(pathname)s:%25(lineno)d%5D')%0A%0A
     trfh
@@ -610,16 +610,49 @@
 utf-8')%0A
+    trfh.setFormatter(formatter)%0A
     logg

Update log to use the new config api, and add a formatter