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
Logging 如何在Wildfly swarm中在单独的文件上配置应用程序审核日志_Logging_Wildfly_Wildfly Swarm - Fatal编程技术网

Logging 如何在Wildfly swarm中在单独的文件上配置应用程序审核日志

Logging 如何在Wildfly swarm中在单独的文件上配置应用程序审核日志,logging,wildfly,wildfly-swarm,Logging,Wildfly,Wildfly Swarm,我已经配置了日志部分,并尝试添加一个额外的处理程序,以使用一个类别将特定日志存储在不同的文件中,方法是在中查找答案,但要适应Wildfly Swarm fluent API 代码如下所示: LoggingFraction loggingFraction = new LoggingFraction() .consoleHandler(level, "COLOR_PATTERN") .formatter("PATTERN", "%d{yyyy-MM-d

我已经配置了日志部分,并尝试添加一个额外的处理程序,以使用一个类别将特定日志存储在不同的文件中,方法是在中查找答案,但要适应Wildfly Swarm fluent API

代码如下所示:

LoggingFraction loggingFraction = new LoggingFraction()
            .consoleHandler(level, "COLOR_PATTERN")
            .formatter("PATTERN", "%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%t] (%c{1}) %s%e%n")
            .formatter("COLOR_PATTERN", "%K{level}%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%t] (%c{1}) %s%e%n")
            .formatter("AUDIT", "%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p (%c{1}) %s%e%n")
            .periodicSizeRotatingFileHandler("FILE", h ->{
                h.level(level)
                        .namedFormatter("PATTERN")
                        .append(true)
                        .suffix(".yyyy-MM-dd")
                        .rotateSize(maxSize)
                        .enabled(true)
                        .encoding("UTF-8")
                        .maxBackupIndex(maxFiles);
                Map<String,String> fileSpec = new HashMap<>();
                fileSpec.put("path", getLogsDirectory() + "/" + "application.log");
                h.file(fileSpec);
            })
            .periodicSizeRotatingFileHandler("FILE_AUDIT_HANDLER", h ->{
                h.level(level)
                        .namedFormatter("AUDIT")
                        .append(true)
                        .suffix(".yyyy-MM-dd")
                        .rotateSize(maxSize)
                        .enabled(true)
                        .encoding("UTF-8")
                        .maxBackupIndex(maxFiles);
                        Map<String,String> fileSpec = new HashMap<>();
                        fileSpec.put("path", getLogsDirectory() + "/" + "application-audit.log");
                        h.file(fileSpec);
            })
            .rootLogger(l -> {
                l.level(level)
                        .handler("CONSOLE")
                        .handler("FILE")
                        ;
            })
            .logger("FILE_AUDIT", l -> {
                l.level(level)
                .category("com.company.app.webservice")
                .level(Level.INFO)
                .handler("FILE_AUDIT_HANDLER")
                ;
            })
            ;
private static final Logger LOGGER_AUDIT = LoggerFactory.getLogger("com.company.app.webservice");
...
LOGGER_AUDIT.info("Testing audit log")
但它不起作用。 我假设类别名称只需要与记录器名称匹配,记录器名称以类别名称“开头”,然后将其包括在内。我说得对吗? 我不知道我的配置是否有问题,或者记录器是否不应该这样使用。

类别属性有点像旧属性。如果有意义的话,记录器名称实际上就是类别。在您的示例中,上面的记录器将命名为FILE_AUDIT,这意味着您希望它与logger.getLoggerFILE_AUDIT匹配

下面的内容可能就是您想要的

LoggingFraction LoggingFraction=新的LoggingFraction .CONSOLEHANDLER级别、颜色和图案 .formatterPATTERN,%d{yyyy-MM-dd HH:MM:ss,SSS}%-5p[%t]%c{1}%s%e%n .formatterCOLOR_图案,%K{level}%d{yyyy-MM-dd HH:MM:ss,SSS}%-5p[%t]%c{1}%s%e%n .formatterAUDIT,%d{yyyy-MM-dd HH:MM:ss,SSS}%-5p%c{1}%s%e%n .periodicSizeRotatingFileHandlerFILE,h->{ h、 水平仪 .namedFormatterPATTERN .真的吗 .suffix.yyyy-MM-dd .旋转轴尺寸 .使能真 .编码UTF-8 .maxBackupIndexmaxFiles; Map fileSpec=新的HashMap; fileSpec.putpath,getLogsDirectory+/+application.log; h、 filespec; } .periodicSizeRotatingFileHandlerFILE\u AUDIT\u HANDLER,h->{ h、 水平仪 .namedFormatterAUDIT .真的吗 .suffix.yyyy-MM-dd .旋转轴尺寸 .使能真 .编码UTF-8 .maxBackupIndexmaxFiles; Map fileSpec=新的HashMap; fileSpec.putpath,getLogsDirectory+/+application-audit.log; h、 filespec; } .rootLoggerl->{ l、 水平仪 .扶手控制台 .handlerFILE ; } .loggercom.company.app.webservice,l->{ l、 水平仪 .levelLevel.INFO .HANDLER文件\u审核\u处理程序 ; } ; 请注意,唯一真正的更改是删除类别(它是只读属性),并将文件\u AUDIT name更改为com.company.app.webservice