Remote rsyslog server records the logs of python script
来源:互联网 发布:远程端口号返回值查询 编辑:程序博客网 时间:2024/05/18 03:45
Ubuntu 14.04.1 LTS
rsyslog server: 10.0.7.77
python client: 10.0.2.122
[rsyslog server]
1.Install rsyslog with apt-get
sudo apt-get install -y rsyslog2.edit /etc/rsyslog.conf ,uncomment this line
$ModLoad immark # provides --MARK-- message capability# provides UDP syslog reception$ModLoad imudp$UDPServerRun 514# provides TCP syslog reception$ModLoad imtcp$InputTCPServerRun 514I will custom my log format,so comment this line:
#$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat
$template myFormat,"[%$NOW% %TIMESTAMP:8:15% %HOSTNAME%] %programname% %msg%\n"set "myFormat" for default tempalte
ps: You can find more format default attributes at http://www.rsyslog.com/doc/property_replacer.html
$ActionFileDefaultTemplate myFormatcreate my log file:
$template DynaFile, "/var/log/falls-%$YEAR%-%$MONTH%-%$DAY%.log":programname,contains,"falls" -?DynaFilefirst line define template named "DynaFile" path is /var/......
second line means if programname contains "falls" then the logs will be recorded in "DynaFile" path.
3.Edit /etc/default/rsyslog,like this:
RSYSLOGD_OPTIONS=" -r514 -m 0"4.restart rsyslog server
sudo service rsyslog restartcheck rsyslog network status:
sudo netstat -anpl | grep 514If you can see 514 port for tcp and udp ,it's successful.
[client]
creat my test.py
<pre name="code" class="python">#!/usr/bin/env python# encoding: utf-8import loggingimport logging.handlersimport randomdef test(): my_logger = logging.getLogger("falls.com") my_logger.setLevel(logging.DEBUG) handler = logging.handlers.SysLogHandler(address = ('10.0.7.77',514)) f = logging.Formatter('falls[10.0.0.1]: %(message)s') handler.setFormatter(f) my_logger.addHandler(handler)<span style="white-space:pre"></span>## Produce different log every time with random number for testing. i = random.randint(1,1000000) #my_logger.debug('This is a test remote log! %d' % i) my_logger.info('fuck: This is a test remote log! %d' % i)if __name__ = '__main__':<span style="white-space:pre"></span>test()
when run test.py,it write a log at rsyslog server:/var/log/falls-DATE.log , the content like this:
[2015-02-08 04:17:55 ip-10-0-2-122] falls fuck: This is a test remote log! 344963
0 0
- Remote rsyslog server records the logs of python script
- CHECK_NRPE: Received 0 bytes from daemon. Check the remote server logs for error messages.
- C# How to get the system drive of remote server
- Records: The concepts of cin.get..
- Execute remote Linux server script from Windows
- [A Weird Bug] caused by the name of Python script
- The problem of deleting the remote branch
- How to collect TrustZone debug logs and check the meaning of error code in the logs
- Second records of career
- Third records of career
- Fourth records of career
- Fifth records of career
- Sixth records of career
- Seventh records of career
- Eighth records of career
- Ninth records of career
- Tenth records of career
- Eleventh records of career
- UVA 11384 Help is needed for Dexter(找规律)
- 关于juqery .post()回调函数不执行的问题
- jQuery支持移动触摸设备的Lightbox插件
- Ubuntu开启SSH服务(相应的openssh安装)& FTP服务(相应的vsftpd安装)
- Devstack使用基础
- Remote rsyslog server records the logs of python script
- 关于豆瓣的分享
- autocomplete在火狐下对中文的支持
- jQuery扁平化单选按钮和复选框美化插件
- Oracle 负载均衡与失效转移
- UVA 10795 A Different Task(递归 状态转移)
- hadoop错误总结
- VirtualBox的菜单栏被隐藏的解决办法
- 理一理空类,空数组的相关问题