首先linux是装在虚拟机上的,我用ifconfig命令看了一下,ip是127.0.0.1.
服务器应该是配置好了,因为在终端写命令local2.info "333",可以写入到新建的log文件里 。
但是用java程序就没反应。
log4j.properties是这样的
log4j.rootLogger=INFO
log4j.appender.syslog=org.apache.log4j.net.SyslogAppender
log4j.appender.syslog.SyslogHost=127.0.0.1
log4j.appender.syslog.Threshold=INFO
log4j.appender.syslog.layout=org.apache.log4j.PatternLayout
log4j.appender.syslog.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n
log4j.appender.syslog.Header=true
log4j.appender.syslog.Facility=local2
java代码是这样的
Logger类
public class Logger {
private Log log = null;
private Logger(Class<?> clazz) {
if (this.log == null) {
PropertyConfigurator.configure(“log4j.properties”);
}
this.log = LogFactory.getLog(clazz);
}
}
主类:
public static void main(String[] args) {
private static final Logger LOG = Logger.getLogger(myclass.class);
LOG.info("111: 111");
LOG.info("222: 222");
LOG.info("333: 333");
}
linux服务器上没有新加的log。
然后我想看有没有连接上服务器,就写了个测试类:
public class CopyOftest {
/**
* @param args
* @throws URISyntaxException
* @throws IOException
* @throws ClientProtocolException
* @throws JAXBException
* @throws IllegalStateException
*/
public static void main(String[] args) throws URISyntaxException, ClientProtocolException, IOException, IllegalStateException, JAXBException {
// TODO Auto-generated method stub
SshClient client = new SshClient();
client.connect("127.0.0.1", 514);// 走这一步出错了,说没有这个host,怎么可能呢?为什么呀?
PasswordAuthenticationClient pwd = new PasswordAuthenticationClient();
pwd.setUsername("root");
pwd.setPassword("root");
int result = client.authenticate(pwd);
if (result == AuthenticationProtocolState.COMPLETE) {
List<SftpFile> list = client.openSftpClient().ls("./Desktop/hehe");
for (SftpFile f : list) {
System.out.println(f.getFilename());
System.out.println(f.getAbsolutePath());
}
}
}
}
另外log4j写日志到linux服务器上 ,只是在配置文件里写个host就能连上吗?还需要别的配置吗?