EDITLogBack Syslog无法正常运行 [英] EDITLogBack Syslog not working java

查看:90
本文介绍了EDITLogBack Syslog无法正常运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个简单的项目,按照以下

I have wrote a simple project to run the log in Ubuntu by follow this example.

ApplicationStarter

package com.javacodegeeks.examples.logbacksyslogexample;

import com.javacodegeeks.examples.logbacksyslogexample.message.IMessageTransmitter;
import com.javacodegeeks.examples.logbacksyslogexample.message.kiwi.KiwiMessageTransmitterImpl;
import com.javacodegeeks.examples.logbacksyslogexample.message.rsyslog.RsyslogMessageTransmitterImpl;

public class ApplicationStarter {

    /**
     * Main method
     */
    public static void main( final String[] args ) {

        final IMessageTransmitter kiwiMessageTransmitter = new KiwiMessageTransmitterImpl();
        kiwiMessageTransmitter.send( "I am learning to send message to Syslog server" );

        final IMessageTransmitter rsyslogMessageTransmitter = new RsyslogMessageTransmitterImpl();
        rsyslogMessageTransmitter.send( "Logback can easily send message to Syslog server" );
    }
}

KiwiMessageTransmitterImpl

package com.javacodegeeks.examples.logbacksyslogexample.message.kiwi;

import com.javacodegeeks.examples.logbacksyslogexample.message.IMessageTransmitter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class KiwiMessageTransmitterImpl implements IMessageTransmitter {

    private static final Logger LOGGER  = LoggerFactory.getLogger( KiwiMessageTransmitterImpl.class );

    @Override
    public void send( final String message ) {
        LOGGER.info( "Hello! My message is : {}", message );
    }
}

RsyslogMessageTransmitterImpl

package com.javacodegeeks.examples.logbacksyslogexample.message.rsyslog;

import com.javacodegeeks.examples.logbacksyslogexample.message.IMessageTransmitter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class RsyslogMessageTransmitterImpl implements IMessageTransmitter {

    private static final Logger LOGGER  = LoggerFactory.getLogger( RsyslogMessageTransmitterImpl.class );

    @Override
    public void send( final String message ) {
        LOGGER.info( "Hello! My message is : {}", message );
    }
}

IMessageTransmitter

package com.javacodegeeks.examples.logbacksyslogexample.message;

public interface IMessageTransmitter {

    void send(final String message);
}

当我运行项目时,我得到的是相同的东西!这 Java发出的消息未发送到syslog

When I run my project , I get the same things! The message from Java are not sending to syslog !

这是 logback.xml .我放在资源文件夹中.

Here the logback.xml. I put in resources folder.

<?xml version="1.0" encoding="UTF-8"?>
<configuration>

    <appender name="KIWI" class="ch.qos.logback.classic.net.SyslogAppender">
        <syslogHost>localhost</syslogHost>
        <facility>LOCAL0</facility>
        <suffixPattern>%thread: %-5level %logger{36} - %msg%n</suffixPattern>
    </appender>

    <appender name="RSYSLOG" class="ch.qos.logback.classic.net.SyslogAppender">
        <!-- Ubuntu Server host name -->
        <syslogHost>centol</syslogHost>
        <facility>LOCAL1</facility>
        <suffixPattern>%thread: %-5level %logger{36} - %msg%n</suffixPattern>
    </appender>

    <logger name="com.javacodegeeks.examples.logbacksyslogexample.message.kiwi" level="INFO">
        <appender-ref ref="KIWI" />
    </logger>

    <logger name="com.javacodegeeks.examples.logbacksyslogexample.message.rsyslog" level="INFO">
        <appender-ref ref="RSYSLOG" />
    </logger>

</configuration>

我使用此命令检查syslog. syslog输出现在看起来正确了.不幸的是,从Netbeans(JAVA)发送的消息仍未在syslog中接收.

I use this command to examine syslog. The syslog output looked correctly now. Unfortunately, the message send from Netbeans(JAVA) still not receiving in the syslog.

尝试cat /var/log/syslog(输出的一小部分)

Try cat /var/log/syslog (small part of the output)

Jun  6 23:37:26 xxx whoopsie[1040]: [23:37:26] online
Jun  6 23:37:26 xxx avahi-daemon[1023]: Registering new address record for 2001:e68:4424:afab:c31f:c843:2351:c58 on wlp6s0.*.
Jun  6 23:37:28 xxx dhclient[19397]: XMT: Solicit on wlp6s0, interval 4340ms.
Jun  6 23:37:32 xxx dhclient[19397]: XMT: Solicit on wlp6s0, interval 9080ms.
Jun  6 23:37:41 xxx dhclient[19397]: XMT: Solicit on wlp6s0, interval 17540ms.
Jun  6 23:37:59 xxx dhclient[19397]: XMT: Solicit on wlp6s0, interval 34190ms.
Jun  6 23:38:09 xxx NetworkManager[1013]: <warn>  [1496763489.9447] dhcp6 (wlp6s0): request timed out
Jun  6 23:38:09 xxx NetworkManager[1013]: <info>  [1496763489.9448] dhcp6 (wlp6s0): state changed unknown -> timeout
Jun  6 23:38:09 xxx NetworkManager[1013]: <info>  [1496763489.9456] dhcp6 (wlp6s0): canceled DHCP transaction, DHCP client pid 19397
Jun  6 23:38:09 xxx NetworkManager[1013]: <info>  [1496763489.9456] dhcp6 (wlp6s0): state changed timeout -> done
user@xxx:/$ 

由于syslogHost和设施的原因,不确定是什么原因.

Not sure is it because of the syslogHost and facility.

推荐答案

最终,我可以正常使用它!真是一场噩梦...

FINALLY I get it to work! What a nightmare...

我遵循 Rsyslog:将日志输出到远程主机来配置Syslog服务器.

转到 rsyslog.conf

sudo vim etc/rsyslog.conf

取消注释这两行.

module(load="imtcp")
input(type="imtcp" port="514")

保存并退出.然后重新启动服务.

Save and exit. Then Restart service.

sudo service rsyslog restart

魔术!

这篇关于EDITLogBack Syslog无法正常运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆