Yosemite 开启日志服务器

2018/05/10 MacOS
知识共享许可协议

配置

   MacOS Yosemite 开启日志服务器,允许远程日志消息打印到系统控制台,可执行如下操作:

  • 打开 UDP 日志接收端口:
    cd /System/Library/LaunchDaemons/
    sudo cp com.apple.syslogd.plist com.apple.syslogd.plist.bak
    sudo /usr/libexec/PlistBuddy -c "add :Sockets:NetworkListener dict" com.apple.syslogd.plist
    sudo /usr/libexec/PlistBuddy -c "add :Sockets:NetworkListener:SockServiceName string syslog" com.apple.syslogd.plist
    sudo /usr/libexec/PlistBuddy -c "add :Sockets:NetworkListener:SockType string dgram" com.apple.syslogd.plist
    sudo launchctl unload com.apple.syslogd.plist
    sudo launchctl load com.apple.syslogd.plist
    
Added Nodes
com.apple.syslogd.plist 新增的节点

  • 查看 UDP 端口是否已经打开:
    # 输出含 UDP 端口号 514,表示配置成功  
    sudo lsof -i :514 -P  
    

Log4j 2 实践

# Syslog Appender 定义
appender.sys.type = Syslog
appender.sys.name = syslog
appender.sys.format = RFC5424
appender.sys.host = Server_IP
appender.sys.port = 514
appender.sys.protocol = UDP
appender.sys.includeMDC = true
appender.sys.layout.type = PatternLayout
appender.sys.layout.pattern = %d{yyyy-MM-dd HH:mm:ss,SSS} [%t] %-5p %c - %m%n  
# 根日志配置成 syslog 的 Appender  
rootLogger.appenderRef.sys.ref = syslog

知识共享许可协议

Search

    mail github location contact

    Table of Contents