Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Grails:用logback替换log4j_Grails_Logging_Log4j_Slf4j - Fatal编程技术网

Grails:用logback替换log4j

Grails:用logback替换log4j,grails,logging,log4j,slf4j,Grails,Logging,Log4j,Slf4j,我试图用logback替换我的Grails应用程序中的log4j,但我总是得到一个 Embedded error: java.lang.reflect.InvocationTargetException org.apache.log4j.LogManager 运行运行应用程序或测试应用程序时 我在BuildConfig.groovy中包含了以下内容,我认为这已经足够了: inherits("global") { excludes "slf4j-log4j12" } [...] de

我试图用logback替换我的Grails应用程序中的log4j,但我总是得到一个

Embedded error: java.lang.reflect.InvocationTargetException
org.apache.log4j.LogManager
运行运行应用程序或测试应用程序时

我在BuildConfig.groovy中包含了以下内容,我认为这已经足够了:

inherits("global") {
    excludes "slf4j-log4j12"
}

[...]

dependencies {
    build 'ch.qos.logback:logback-core:0.9.29', 'ch.qos.logback:logback-classic:0.9.29'
    runtime 'ch.qos.logback:logback-core:0.9.29', 'ch.qos.logback:logback-classic:0.9.29'
}
我找不到更多关于Log4J的引用,也不知道这个电话是从哪里打来的

我还尝试将Grails slf 1.5.8替换为1.6.2,并在控制台中获得以下内容,尽管已将slf从所有Grails模块中排除:

SLF4J: The requested version 1.6 by your slf4j binding is not compatible with [1.5.5, 1.5.6, 1.5.7, 1.5.8]
SLF4J: See http://www.slf4j.org/codes.html#version_mismatch for further details.
提前谢谢你的帮助

问候,


Jonas

Logback 0.9.21及以上版本取决于slf4j api 1.6,这正是错误告诉您的

为org.slf4j:slf4j api:1.6添加依赖项这对我在BuildConfig.groovy中使用Grails 2.1.0时很有用:

inherits("global") {
    excludes 'grails-plugin-log4j'        
}
[……]

[……]


最后一行使Grails正确地读取Grails app/conf/logback.groovy,如果您想在其中设置配置。

我使用了logback 1.0.6。它不起作用。但我用另一种方式。设置环境变量“logback.configurationFile={groovy file address}”。例如:

grails run-app -Dlogback.configurationFile=c:\log\logback.groovy
您可以在tomcat或任何其他将war文件放入其中的文件中使用此参数


这对我很有用。

几天前我将Logback集成到Grails中-我的工作解决方案步骤如下:

此外,还有一个新的插件“绕过区块”:这似乎很有希望


祝你在这个问题上好运-值得努力

这可能对其他人有帮助:

在config.groovy中指定配置

logback = {
    appenders {
        console name: 'stdout', encoder: pattern(pattern: "%d{dd-MMM-yyyy HH:mm:ss} %-5p %c - %m%n")

        rollingFile(
                name: 'fileAppender',
                file: logFileName,
                encoder: pattern(pattern: "%d{dd-MMM-yyyy HH:mm:ss} %-5p %c - %m%n"),
                triggeringPolicy: new SizeBasedTriggeringPolicy(maxFileSize: 10*1024*1024), // Max is 10 MB log files
                rollingPolicy: new FixedWindowRollingPolicy(fileNamePattern: iLogFileName)
        )
    }

    error fileAppender: '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'

    info fileAppender: 'org.springframework.web.client',
            'com.yourpackage',
            'com.linkedin.grails'


    debug fileAppender: 'com.yourpackage',  // Set debug level for non-grails artifacts, e.g. src/groovy, under the com.yourpackage.package
            'grails.app' // Set debug level for all application artifacts

    trace fileAppender: 'org.springframework.web.client',
            'org.springframework.social',
            'com.yourpackage'

    root {
        info 'stdout', 'fileAppender'
    }
}
 inherits("global") {
        excludes 'grails-plugin-log4j', 'log4j'  //using logback as grails-log4j have serialization issues with spark libraries
    }
  • 包括logback插件并排除所需的软件包:
  • 在BuildConfig.groovy中

    logback = {
        appenders {
            console name: 'stdout', encoder: pattern(pattern: "%d{dd-MMM-yyyy HH:mm:ss} %-5p %c - %m%n")
    
            rollingFile(
                    name: 'fileAppender',
                    file: logFileName,
                    encoder: pattern(pattern: "%d{dd-MMM-yyyy HH:mm:ss} %-5p %c - %m%n"),
                    triggeringPolicy: new SizeBasedTriggeringPolicy(maxFileSize: 10*1024*1024), // Max is 10 MB log files
                    rollingPolicy: new FixedWindowRollingPolicy(fileNamePattern: iLogFileName)
            )
        }
    
        error fileAppender: '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'
    
        info fileAppender: 'org.springframework.web.client',
                'com.yourpackage',
                'com.linkedin.grails'
    
    
        debug fileAppender: 'com.yourpackage',  // Set debug level for non-grails artifacts, e.g. src/groovy, under the com.yourpackage.package
                'grails.app' // Set debug level for all application artifacts
    
        trace fileAppender: 'org.springframework.web.client',
                'org.springframework.social',
                'com.yourpackage'
    
        root {
            info 'stdout', 'fileAppender'
        }
    }
    
     inherits("global") {
            excludes 'grails-plugin-log4j', 'log4j'  //using logback as grails-log4j have serialization issues with spark libraries
        }
    
    内部依赖项:包括编译“org.grails.plugins:logback:0.3.1”

  • 禁用Fork模式执行。它将不会与logback一起工作

  • 以上配置仅适用于WAR模式

  • 如果您甚至想在正常的本地开发模式下控制日志记录,请在conf目录中包含logback.xml文件

  • logback.xml:

    <?xml version="1.0" encoding="UTF-8" ?>
    
    <configuration>
        <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
            <encoder>
                <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
            </encoder>
        </appender>
    
        <root level="warn">
            <appender-ref ref="STDOUT"/>
        </root>
        <shutdownHook/>
    </configuration>
    
    
    %d{HH:mm:ss.SSS}[%thread]-5级别%logger{36}-%msg%n
    
    排除
    grails-plugin-log4j
    是关键
    Logback。groovy从WAR运行时不起作用,因为它被编译到Logback.class,Logback会查找源代码