如何从命令行写入日志文件
/var/log/syslog
?logger
命令。logger Some message to write
-i Log the process ID in each line
-f Log the contents of a specified file
-n Write to the specified remote syslog server
-p Specify a priority
-t Tag the line with a specified tag
有关该工具的更多信息,请参阅 man 1 logger
。
syslog
。python -c 'import syslog; syslog.syslog("Hello World")'
logger
更好。我已经支持你了,只是提供一个替代方案。 - Sylvain Pineaulogger -p local0.notice -t ${0##*/}[$$] Hello world
中间的胡言乱语将被翻译为调用程序。因此,如果您检查syslog底部,您将看到类似于以下内容:
May 07 08:27:14 ip-10-1-11-166 -bash[42108]: Hello world
logger
示例以及通过netcat
或shell重定向进行远程记录,请参阅:https://www.safaribooksonline.com/library/view/bash-cookbook/0596526784/ch15s14.html - user13975