Linux logger and linux logger
Logger is used to write logs to the system. It provides a shell command interface to the syslog system module.
Logger syntax
Logger [options] [messages]
** Options: **-d, -- udp uses the datagram (UDP) instead of the default stream connection (TCP)-I, -- id records the process ID-f of each logger row by row, -- file file_name records the specific file-h, -- help displays the help text and exits-n, -- server writes data to the specified remote syslog server and uses UDP instead of the built-in syslog routine-P, -- port port_num uses the specified UDP port. The default port number is 514-p, -- priority priority_level, which specifies the priority of the input message. The priority can be a number or the format specified as "facility. level. For example, the message level of "-p local3.info" local3 is info. The default value is "user. notice"-s, -- stderr outputs standard errors to system logs. -T, -- tag specifies the tag record-u, -- socket writes to the specified socket, rather than to the built-in system log routine. -V, -- version the actual version information and exit ** messages: ** the message that is written to the log file. It can be used with-f. Logger exits with 0, indicating success. If it is greater than 0, it indicates failure.
Log Level
Facility: auth: user authorization authpriv: Authorization and Security cron: scheduled task daemon: System daemprocess kern: kernel-related information lpr and print service-related information mail and email-related information news information from the news server syslog information generated by the user program, the default uucp information generated by uucp is local0 ~ 7. used to define the local policy level: alert needs to take immediate action crit critical status debug emerg system unavailable err error status info normal message notice normal but note
Example:
$ Logger System Rebooted # write "System Rebooted" to the System log routine, which can be viewed in/var/log/syslog.
Example of writing data to a specified log file:
$ Vi/etc/rsyslog. conf # My system is ubuntu1204, adding local3. */var/log/my_test.log to the last line indicates that all messages from local3 are recorded in/var/log/my_test.log $ service rsyslog restart # restart rsyslog service $ logger- i-t "my_test"-p local3.notice "test_info" $ cat/var/log/my_test.log May 5 21:27:37 gino-virtual-machine my_test [3651]: test_info