logging - How to configure application audit log on a separate file in Wildfly-swarm -


i have configured logging fraction , tried add additional handler store specific logs in different files, using category, looking answer in how log application auditing separate file on wildfly 8 adapting wildfly-swarm fluent api.

the code looks this:

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")                 ;             })             ; 

then created normal logger in code add log, this:

private static final logger logger_audit = loggerfactory.getlogger("com.company.app.webservice"); ... logger_audit.info("testing audit log") 

but doesn't work.
i'm assuming category name needs match logger name, in way logger name 'starts with' category name, included. right?
don't know if there's wrong in configuration or if logger not supposed used that.

the category attribute bit of legacy attribute. logger name category if makes sense. in example above logger named file_audit means you'd match logger.getlogger("file_audit").

something following want.

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("com.company.app.webservice", l -> {                 l.level(level)                 .level(level.info)                 .handler("file_audit_handler")                 ;             })             ; 

note real change removing category (it's read-only attribute) , changing file_audit name com.company.app.webservice.


Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -