Think before you speak, read before you think.

rsyslog以及logger命令

配置 rsyslog

cat /etc/rsyslog.d/custom_logging.conf

# 定义模板
$template CUSTOM_LOGS,"/var/log/%programname%.log"
if ($programname == 'my_custom_app') then ?CUSTOM_LOGS
# 匹配到后停止后续匹配
&~

if ($programname startswith 'm') then ?CUSTOM_LOGS
&~

使用 logger 测试上面的配置

logger -t my_custom_app "==================>my_custom_app" 会记录到 /var/log/my_custom_app.log 
logger -t my_custom_app_1 "==================>my_custom_app_1" 会记录到 /var/log/my_custom_app_1.log

logger命令是syslog的shell接口

测试上面的配置

把文件记录到syslog里

logger -f filename

后面直接跟要记录的文本

logger jpuyy.com

可以看到这样一条记录

Sep 13 16:55:51 iZ28bz7jrdyZ root: jpuyy.com

参考:

http://help.papertrailapp.com/discussions/questions/96-how-to-log-a-message-from-the-linux-command-line.html


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *