Linux命令(116)之logger

本文详细介绍了Linux系统中的logger命令,包括其作用、常用参数(如记录进程ID、添加标签、指定日志级别等)、查看版本和帮助信息,以及实际操作日志记录的示例。
摘要由CSDN通过智能技术生成

linux命令之logger

1.logger介绍

linux命令logger是一个shell命令接口,通过该接口使用rsyslog的系统日志模块可以向系统日志文件(自定义日志文件)写入一行信息

2.logger用法

logger [参数] [message]

logger参数
参数说明
-i记录进程ID
-t在日志中的每一行添加一个标签
-p指定自定义的日志设备和对应的日志级别
-V查看版本信息

3.实例

3.1.查看版本信息

命令:

logger -V

[root@rhel77 ~]# logger -V
logger from util-linux 2.23.2
[root@rhel77 ~]# 

3.2.查看帮助信息

命令:

logger --help

[root@rhel77 ~]# logger --help

Usage:
 logger [options] [message]

Options:
 -T, --tcp             use TCP only
 -d, --udp             use UDP only
 -i, --id              log the process ID too
 -f, --file <file>     log the contents of this file
 -h, --help            display this help text and exit
 -S, --size <num>      maximum size for a single message (default 1024)
 -n, --server <name>   write to this remote syslog server
 -P, --port <port>     use this port for UDP or TCP connection
 -p, --priority <prio> mark given message with this priority
 -s, --stderr          output message to standard error as well
 -t, --tag <tag>       mark every line with this tag
 -u, --socket <socket> write to this Unix socket
 -V, --version         output version information and exit

[root@rhel77 ~]# 

3.3.模式系统日志

命令:

logger -it error -p local5.crit "hello world"

[root@rhel77 ~]# logger -it error -p local5.crit "hello world"
[root@rhel77 ~]# tail -n 1 /var/log/ztj.log       #/var/log/ztj.log为自定义日志文件
127.0.0.1 error 2 hello-world hello world
[root@rhel77 ~]# 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小黑要上天

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值