grails - 我的log4j配置不会产生任何输出

时间:2016-06-21 09:28:38

标签: grails log4j

我试图在我的webapp中使用log4j,我根据this博客中的例子写了一个log4j配置。

创建了文件,但没有输出。我尝试了不同的配置但没有成功

Config.groovy中

<?php
if ($_POST['textEmail'] != '') {
    $text = str_replace(" ", '&nbsp;', $_POST['textEmail']);
    $pattern = '/([a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6})/';
    preg_match_all($pattern,file_get_contents("update.txt"), $matches);
    $emails = $matches[0];   // get Array of all email in file 
    if (!in_array($text, $emails)) {     // echck for existing email 
        file_put_contents("update.txt", PHP_EOL.$_POST['textEmail'], FILE_APPEND);
    }else{
        echo 'Email address alerady exist';
    }
   echo  $f = file_get_contents("update.txt");
}
?>

控制器

def log4jFileName = System.properties.getProperty('catalina.base', '.') + "/logs/myapp.log"
def log4jStacktrace = System.properties.getProperty('catalina.base', '.') + "/logs/stacktrace.log"

environments {
    development {
        log4jFileName = "logs/myapp.log"
    }
    test {
        log4jFileName = "logs/myapp.log"
    }
}

log4j = {
    def pattern = new PatternLayout("[%p] [%c{3}] %m%n")

    appenders {
        appender new DailyRollingFileAppender(
                        name:"file",
                        file:log4jFileName,
                        layout: pattern,
                        datePattern: "'.'yyyy-MM-dd",
                        threshold: Level.toLevel("DEBUG")
                    )

        rollingFile name:"stacktrace",
            file:log4jStacktrace,
            maxFileSize:'5MB',
            layout: pattern,
            datePattern: "'.'yyyy-MM-dd"

        console name:"stdout",
                layout: pattern,
                datePattern: "'.'yyyy-MM-dd"
    }

    root { 
        environments {
            production {
                debug "file", "stacktrace"
            }
            development {
                debug "file", "stdout"
            }
        }
    }

    error   'org.codehaus.groovy.grails.web.servlet',        // controllers
            'org.codehaus.groovy.grails.web.pages',          // GSP
            'org.codehaus.groovy.grails.web.sitemesh',       // layouts
            'org.codehaus.groovy.grails.web.mapping.filter', // URL mapping
            'org.codehaus.groovy.grails.web.mapping',        // URL mapping
            'org.codehaus.groovy.grails.commons',            // core / classloading
            'org.codehaus.groovy.grails.plugins',            // plugins
            'org.codehaus.groovy.grails.orm.hibernate',      // hibernate integration
            'org.springframework',
            'org.hibernate',
            'net.sf.ehcache.hibernate'

    warn    'org.springframework',
            'org.hibernate',
            'grails.plugins.springsecurity',
            'groovyx.net.http'

    debug   'grails.app'

}

0 个答案:

没有答案