grails log4j 根据文件不同的附加程序 [英] grails log4j diffrerent appenders according files

查看:26
本文介绍了grails log4j 根据文件不同的附加程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想根据模块登录到不同的附加程序...

I would like to log to different appenders depending on the module...

我有 3 个 appender:控制台,一个用于记录控制器和服务的滚动文件,以及另一个用于记录作业中某些内容的滚动文件.我只想为它的滚动文件记录作业的代码,并仅使用其他滚动文件记录控制器和服务.

I have 3 appenders: the console, a rolling file to log the controller and services, and another rolling file to log some stuff in jobs. I want to log the code of the job only for its rolling file and to log the controllers and services only with the other rolling file.

这是我的 grails log4j 配置:

So this is my grails log4j configuration:

development {   
    def catalinaBase = System.properties.getProperty('catalina.base')
    if (!catalinaBase) catalinaBase = '.'
    def logDirectory = "${catalinaBase}/logs/AmbienticWebsite"


    log4j = {

        appenders {
            console name:'stdout', layout:pattern(conversionPattern: '%c{2} [%p] - %m%n')
            appender new DailyRollingFileAppender(
                    name: "rollingFileGrailsApp",
                    file: "${logDirectory}/GrailsApp.log",
                    datePattern: "'.'yyyy-MM-dd",
                    layout: pattern(conversionPattern: commonPattern)
            )
            appender new DailyRollingFileAppender(
                name: "rollingFileImport",
                file: "${logDirectory}/Imports.log",
                datePattern: "'.'yyyy-MM-dd",
                layout: pattern(conversionPattern: commonPattern)
            )
        }

        root {
            error 'stdout', 'rollingFileImport', 'rollingFileGrailsApp' // both stdout and AmbienticWebsite_dev.log are filled by logging information
            additivity = false
        }

          debug rollingFileImport: 'ambienticwebsite.EventImportJob',
                                    'time2marketing.time2marketingImportService',
                                    'eventImportData.DiscomImportDataService',
                                    'eventImportData.EventImportService'

          info rollingFileGrailsApp: 'ambienticwebsite', 
                'ambienticwebsite.jobManagement.AmbienticJobListener',
                'BootStrap',
                'grails.app.controllers',
                'grails.app.services'       
    }
}

通过这种配置,日志被写入两个滚动文件和标准输出.如果我从根目录中删除滚动附加程序,滚动文件将保持为空,即使为文件组指定了附加程序也是如此.

With this configuration, the logs are written to the two rolling files and stdout. If I delete the rolling appenders from the root, the rolling file stays empty, even if the appenders are specified for the group of files.

有没有人建议将日志分成附加程序?

Does anyone have advice to separate the log into the appenders?

推荐答案

我认为您需要将 additivity: false 添加到自定义 appender.

I think you need to add additivity: false to the custom appenders.

debug rollingFileImport: [foo, bar, baz]
      additivity: false

info rollingFileGrailsApp: [foo1, bar1, baz1]
     additivity: false

参考 grails 中的 Logger 继承.

Refer Logger Inheritance in grails.

这篇关于grails log4j 根据文件不同的附加程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆