logger 命令

发布时间: 更新时间: 总字数:378 阅读时间:1m 作者: IP上海 分享 网址

logger 命令用于将 Linux 日志写入系统日志

介绍

系统日志文件:

  • CentOS/Redhat 写入 /var/log/message 文件中
  • Ubuntu 写入 /var/log/syslog 文件中

安装

apt install bsdutils

help

logger --help ...
$ logger --help

Usage:
 logger [options] [<message>]

Enter messages into the system log.

Options:
 -i                       log the logger command's PID
     --id[=<id>]          log the given <id>, or otherwise the PID
 -f, --file <file>        log the contents of this file
 -e, --skip-empty         do not log empty lines when processing files
     --no-act             do everything except the write the log
 -p, --priority <prio>    mark given message with this priority
     --octet-count        use rfc6587 octet counting
     --prio-prefix        look for a prefix on every line read from stdin
 -s, --stderr             output message to standard error as well
 -S, --size <size>        maximum size for a single message
 -t, --tag <tag>          mark every line with this tag
 -n, --server <name>      write to this remote syslog server
 -P, --port <port>        use this port for UDP or TCP connection
 -T, --tcp                use TCP only
 -d, --udp                use UDP only
     --rfc3164            use the obsolete BSD syslog protocol
     --rfc5424[=<snip>]   use the syslog protocol (the default for remote);
                            <snip> can be notime, or notq, and/or nohost
     --sd-id <id>         rfc5424 structured data ID
     --sd-param <data>    rfc5424 structured data name=value
     --msgid <msgid>      set rfc5424 message id field
 -u, --socket <socket>    write to this Unix socket
     --socket-errors[=<on|off|auto>]
                          print connection errors when using Unix sockets
     --journald[=<file>]  write journald entry

 -h, --help               display this help
 -V, --version            display version

For more details see logger(1).

使用示例

logger -h
man logger

logger "This is just a simple log line"
# -p 指定输入消息日志级别
logger -p "local3.info" "This is just a simple log line"

# to syslog
logger -n 192.168.1.10 "This is just a simple log line"
logger -n 192.168.1.10  -P 1514 "This is just a simple log line"

# to syslog use tcp
logger -n 192.168.1.10 -T "This is just a simple log line"

# -i 指定进程id;-t 指定模块名;-s 输出标准错误
logger -i -t xxxx -s "This is just a simple log line"
Home Archives Categories Tags Statistics
本文总阅读量 次 本站总访问量 次 本站总访客数