syslog日志记录



syslog两个规范:

RFC3164(被RFC5424替代了):UDP
RFC3195                 :TCP

syslog两个重要的文件:

/etc/syslogd(守护进程)
/etc/syslog.conf配置文件,有些系统没有该文件

syslog三个重要函数

void openlog(const char *ident, int option, int facility);

void syslog(int priority, const char *format, ...);

void closelog(void);

openlog option取值说明

option参 数说 明
LOG_CONS如果将信息发送给syslogd守护进程时发生错误,直接将相关信息输出到终端
LOG_NDELAY立即打开与系统日志的连接(通常情况下,只有在产生第一条日志信息的情况下才会打开与日志系统的连接)
LOG_NOWAIT在记录日志信息时,不等待可能的子进程的创建
LOG_ODELAY类似于LOG_NDELAY参数,与系统日志的连接只有在syslog函数调用时才会创建
LOG_PERROR在将信息写入日志的同时,将信息发送到标准错误输出(POSIX.1-2001不支持该参数)
LOG_PID每条日志信息中都包括进程号

openlog facility取值说明

facility参数syslog.conf中对应的facility取值
LOG_KERNkern
LOG_USERuser
LOG_MAILmail
LOG_DAEMONdaemon
LOG_AUTHauth
LOG_SYSLOGsyslog
LOG_LPRlpr
LOG_NEWSnews
LOG_UUCPuucp
LOG_CRONcron
LOG_AUTHPRIVauthpriv
LOG_FTPftp
LOG_LOCAL0~LOG_LOCAL7local0~local7
syslog priority取值说明
priority参数syslog.conf中对应的level取值
LOG_EMERGemerg
LOG_ALERTalert
LOG_CRITcrit
LOG_ERRerr
LOG_WARNINGwarning
LOG_NOTICEnotice
LOG_INFOinfo
LOG_DEBUGdebug



syslogd的几个命令

	Usage: syslogd [OPTIONS]

	System logging utility

			-n              Run in foreground
			-R HOST[:PORT]  Log to HOST:PORT (default PORT:514)
			-L              Log locally and via network (default is network only if -R)
			-C[size_kb]     Log to shared mem buffer (use logread to read it)
			-K              Log to kernel printk buffer (use dmesg to read it)
			-O FILE         Log to FILE (default:/var/log/messages, stdout if -)
			-s SIZE         Max size (KB) before rotation (default:200KB, 0=off)
			-b N            N rotated logs to keep (default:1, max=99, 0=purge)
			-l N            Log only messages more urgent than prio N (1-8)
			-S              Smaller output
			-D              Drop duplicates
			-f FILE         Use FILE as config (default:/etc/syslog.conf)

a.启动syslog日志守护进程的命令

#/sbin/syslogd 

b.传log日志to server

#/sbin/syslogd -R HOST:PORT

c.关闭所有日志文件,重读/etc/syslog.conf配置文件后重新开始记录日志

#killall  -HUP  syslogd 

d.syslog启动脚本例子
	#/etc/init.d/rcS
	/bin/mkdir /home/log
	killall syslogd
	#上传给syslogserver,只上传给server,本地不存储
	/sbin/syslogd -O /home/log/xxxxx.log -s 2560 -R 192.168.65.100:514
	#/sbin/syslogd -O /home/log/xxxxx.log -s 2560 -L -R 192.168.65.100:514 #server+本地
	cp /var/log/messages /home/log/messages

工具使用

a.syslogwather:
参考文章:http://blog.csdn.net/lsh6688/article/details/38324447
官网下载: https://syslogwatcher.com/syslog-watcher/
和谐下载:

b.另一个工具      :Kiwi SyslogServer


c.nxlog http://nxlog.org/products/nxlog-community-edition/download



参考

http://book.51cto.com/art/201406/442921.htm
http://blog.chinaunix.net/uid-26583794-id-3166083.html

syslogd以及syslog.conf文件解读说明:http://www.cnblogs.com/doctorqbw/archive/2012/07/31/2616322.html

关于syslog报文的RFC规范:http://blog.csdn.net/fishmai/article/details/51838681

http://nxlog.org/products/nxlog-community-edition/download
  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值