java - About log4j 2.0 configuration -
i trying use log4j2 in project logging. conf file named log4j2.xml directly under java project , have necessary jars in classpath. when test if logging works correctly conf file below, see error messages although expect see info messages too. know problem here?
log4j2.xml
<?xml version="1.0" encoding="utf-8"?> <configuration> <properties> <property name="servicename">m2mp_checker</property> <property name="patterntime">%d{yyyy-mm-dd hh:mm:ss.sss} | %-5.5p | %-10.10t | %-20.20c:%-5.5l | %msg%n</property> <property name="patternnotime">%-5.5p | %-10.10t | %-20.20c:%-5.5l | %msg%n</property> </properties> <appenders> <console name="console" target="system_out"> <patternlayout pattern="${patterntime}"/> </console> </appenders> <loggers> <root level="info"> <appender-ref ref="console"/> </root> </loggers> </configuration>
java code:
package test; import org.apache.logging.log4j.logmanager; import org.apache.logging.log4j.logger; import com.jcraft.jsch.*; /** * @author : t12888 */ public class tester { private static final logger logger = logmanager.getlogger(tester.class); public static void main(string[] args) { string username = "aa"; string host = "aa"; string pass = "aa"; string khfile = "/home/testuser/.ssh/known_hosts"; string identityfile = "/home/testuser/.ssh/id_rsa"; jsch jsch = null; session session = null; channel channel = null; channelsftp c = null; try { java.util.properties config = new java.util.properties(); config.put("stricthostkeychecking", "no"); jsch = new jsch(); session = jsch.getsession(username, host, 22); session.setpassword(pass); session.setconfig(config); session.connect(); channel = session.openchannel("sftp"); channel.connect(); c = (channelsftp) channel; } catch (exception e) { e.printstacktrace(); } try { logger.info("info"); string fsrc = "abc.xml", fdest = "abc.xml"; c.put(fsrc, fdest); c.get(fdest, "/tmp/testfile.bin"); } catch (exception e) { logger.error("error"); e.printstacktrace(); } finally{ c.disconnect(); session.disconnect(); } } }
output:
11:27:45.873 [main] error test.tester - error
i think forget set ${patterntime}
set this: system.setproperty("patterntime", your_patterntime);
Comments
Post a Comment