Dre*_*kes 50
使用logger命令。
logger Some message to write
Run Code Online (Sandbox Code Playgroud)
有多种选择,包括:
-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
Run Code Online (Sandbox Code Playgroud)
有关man 1 logger该工具的更多信息,请参见。
Syl*_*eau 10
或者,您可以syslog从 python写入:
python -c 'import syslog; syslog.syslog("Hello World")'
Run Code Online (Sandbox Code Playgroud)
作为一名开发人员,我很少有时间仔细研究man页面,所以 TLDR:
logger -p local0.notice -t ${0##*/}[$$] Hello world
Run Code Online (Sandbox Code Playgroud)
中间的乱码将转换为调用程序。因此,如果您检查系统日志的底部,您会看到类似以下内容:
May 07 08:27:14 ip-10-1-11-166 -bash[42108]: Hello world
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
46418 次 |
| 最近记录: |