Logger is used to write logs to the system, he provides a shell command interface to the Syslog system module, and can write a line of information directly to the system log file from the command line, and the default log is saved in/var/log/messages.
Logger syntax
logger [options] [messages]
**options (option): * *
-d,--udp
using datagrams (UDP) instead of using the default streaming connection (TCP)
-i,--id
&NB SP; logger process ID
 -F,--file file_name
record specific files
-h, per line -help
Display Help text and exit
-n,--server
write to the specified remote Syslo g server, using UDP instead of routines in the built-in syslog
-s,--stderr
output standard error to system log.
-t,--tag tag
Specify tag record
-u,--socket socket
&NBS P writes the specified socket instead of to the built-in system log routines.
-v,--version
display version information and exit
-P,--port port_num
Uses the specified UDP port. The default port number is 514
-P,--priority priority_level
Specifies the input message log level, which can be a number or a format specified as "Facility.level". For example: "-P local3.info" local3 the message level of this device is info. The default level is "User.notice"
Facility:
Auth: User Authorization
AUTHPRIV: Authorization and security
Cron: Scheduling Tasks
Daemon: System daemon
Kern: Kernel-related information
LPR information about the print service
Mail-related information
News information from the press server
Syslog-generated information by syslog
Information generated by the user's program, default
UUCP information generated by UUCP
Local0~7 used to define local policies
Level
Alert needs to take immediate action.
Crit Critical state
Debug debugging
Emerg System not available
Error state
Info Normal Message
Notice normal, but be careful.
**messages:** writes the content message to the log file, which can be used in conjunction with-F.
Logger with 0 exit indicates success, and greater than 0 indicates failure.
Write a line of information directly from the command line to the system log file
[Email protected] ~]# logger-it logger_test-p user.info logger_messages_text[[email protected] ~]# cat/var/log/message S|grep logger_testdec 1 16:44:51 localhost logger_test[6369]: Logger_messages_text[[email protected] ~]#
Example:
Port forwarding via iptables, Access 10.15.44.239:6001 to 10.15.44.242:80 (Nginx), and access 10.15.44.239:6002 to 10.15.44.242:8080 (Tomcat).
by logger.
net.ipv4.ip_forward = 1[[email protected] ~]# iptables -t nat -a prerouting -d 10.15.44.239 -p tcp --dport 6001 -j dnat -- To-destination 10.15.44.242:80[[email protected] ~]# iptables -t nat -a postrouting -s0.0.0.0/0 -p tcp --dport 80 -j snat --to-source 10.15.44.239[[email protected] ~]# iptables -t nat -a prerouting -d 10.15.44.239 -p tcp --dport 6002 -j dnat --to-destination 10.15.44.242:8080[[email protected] ~]# iptables -t nat -A postrouting -s0.0.0.0/0 -p tcp --dport 8080 -j snat --to-source 10.15.44.239[[email protected] ~]# iptables -t mangle -a postrouting - J log --log-level 4 --log-prefix "Out packets:" [[email protected] ~]# /etc/rsyslog.conf   #/CENTOS6 before/etc/syslog.confkern.warning /var/log/iptables #文末添加此行 [[ Email protected] ~]# cat /etc/init.d/rsyslog restart
[[email protected] ~]# tail -f /var/log/iptables.log | grep src= 10.15.44.18 | grep dpt=8080dec 1 15:35:58 localhost kernel: out PACKETS:IN= OUT=eth1 SRC=10.15.44.18 DST=10.15.44.242 LEN=568 TOS=0x00 prec=0x00 ttl=63 id=25667 df proto=tcp spt=57904 dpt=8080 window=16240 res=0x00 ack psh urgp=0 dec 1 15:35:58 localhost kernel: out packets:in= out=eth1 src=10.15.44.18 dst=10.15.44.242 len=40 tos=0x00 prec=0x00 ttl=63 id=25668 df proto=tcp spt=57904 dpt=8080 window= 16425 res=0x00 ack urgp=0[[email protected] ~]# tail -f /var/log/ Iptables.log | grep src=10.15.44.18 | grep dpt=80dec 1 15:36:16 localhost kernel: out  packets:in= out=eth1 src=10.15.44.18 dst=10.15.44.242 len=52 tos=0x00 prec=0x00 ttl=63 id=28033 df proto=tcp spt=58176 dpt=80 window=8192 res=0x00 syn urgp=0 dec 1 15:36:16 localhost kernel: out packets:in = out=eth1 src=10.15.44.18 dst=10.15.44.242 len=40 tos=0x00 prec=0x00 ttl= 63 id=28034 df proto=tcp spt=58175 dpt=80 window=16425 res=0x00 ack URGP=0 Dec 1 15:36:16 localhost kernel: OUT PACKETS:IN= out=eth1 src=10.15.44.18 dst=10.15.44.242 len=40 tos=0x00 prec=0x00 ttl=63 id=28035 df proto=tcp spt=58176 dpt=80 window=16425 res=0x00 ack urgp= 0
At this point, we don't have iptables forwarded information in/var/log/messages.
[Email protected] ~]# Tail-f/var/log/messages | grep src=10.15.44.18 | grep dpt=80
Without any information output
Now go through the logger to read the/var/log/iptables, will 10.15.44.18 come over to access 80 port information to write to the system log
[Email protected] ~]# tail-f/var/log/iptables.log |grep src=10.15.44.18 | grep dpt=80 | Logger-it iptables_log-p User.info
We'll have a new meeting, see/var/log/messages and see 10.15.44.18 coming over. Access Port 80 Information
[[email protected] ~]# tail -f /var/log/messages | grep src= 10.15.44.18 | GREP DPT=80DEC  1 16:50:08 LOCALHOST IPTABLES_LOG[6383]: Dec 1 16:49:58 localhost kernel: OUT PACKETS:IN= OUT=eth1 src=10.15.44.18 dst=10.15.44.242 len=40 tos=0x00 prec=0x00 ttl=63 id=7307 Df proto=tcp spt=60350 dpt=8080 window=16000 res=0x00 ack urgp=0 dec 1 16:50:08 localhost iptables_log[6383]: Dec 1 16:49:58 localhost kernel: out packets:in= out=eth1 src=10.15.44.18 dst=10.15.44.242 LEN=40 TOS=0x00 PREC=0x00 TTL=63 ID=7308 DF PROTO=TCP SPT=60350 dpt=8080 window=16425 res=0x00 ack urgp=0 dec 1 16:50:08 Localhost iptables_log[6383]: dec 1 16:49:58 localhost kernel: out packets:in= out=eth1 src=10.15.44.18 dst=10.15.44.242 len=515 tos=0x00 prec=0x00 ttl=63 id=7309 Df proto=tcp spt=60253 dpt=8080 window=16394 res=0x00 ack psh urgp=0
This article is from "I am not a rookie" blog, please be sure to keep this source http://pvbutler.blog.51cto.com/7662323/1878576
The logger of Linux commands