where log4j2.xml should placed use in applet? can log both java console , files on user computer?
i placed in applet resources conf/log4j2.xml , read applet. applet loads incorrectly, fix fields applet code:
public static logger getlogger(class classname) { //get logger configuration loggercontext loggercontext = configurator.initialize("client", classname.getclassloader(), classname.getclassloader().getresource("conf/log4j2.xml").getfile()); configuration configuration = loggercontext.getconfiguration(); //set root logger desired level loggerconfig loggerconfig = configuration.getloggerconfig(""); loggerconfig.setlevel(level.info); //obtain appender appender appender = obtainappender(configuration); //get logger required class org.apache.logging.log4j.core.logger loggerforclass = loggercontext.getlogger(classname.getname()); //associate logger required class created appender configuration.addloggerappender(loggerforclass, appender); return loggerforclass; } private static appender obtainappender(configuration configuration) { //create appender triggeringpolicy[] triggeringpolicies = {onstartuptriggeringpolicy.createpolicy(), timebasedtriggeringpolicy.createpolicy("5", "true"), sizebasedtriggeringpolicy.createpolicy("5 mb")}; triggeringpolicy triggeringpolicy = compositetriggeringpolicy.createpolicy(triggeringpolicies); return rollingfileappender.createappender(client_log_path + fileutils.file_separator + "my_client.log", client_log_path + fileutils.file_separator + "/$${date:yyyy-mm}/my_client-%d{mm-dd-yyyy-hh-mm}-%i.log", "", applet_appender, "true", "true", triggeringpolicy, null, patternlayout.createlayout("%d{dd/mm/yyyy hh:mm:ss} %-5p [%t] [%c{1}] %m%n", configuration, null, "utf-8"), null, "true", configuration); }
Comments
Post a Comment