我有一个 systemd 服务,它输出到日志文件
StandardOutput=file:/path/to/log/file
StandardError=file:/path/to/error/file
Run Code Online (Sandbox Code Playgroud)
我怎样才能在这些输出和错误前面添加数据+时间,以便它读取
10-09-2019 12:43:23 The output here.
Run Code Online (Sandbox Code Playgroud)
试试这个(警告:未经测试)
Enable和Start一个“logging.service”systemctl
在[Service]定义中logging.service使用以下内容:
[Unit]
Description=Start logging server # or whatever you choose to call it
[Service]
...
Type=forking
ExecStart=/bin/bash myLogger.sh start
...
Run Code Online (Sandbox Code Playgroud)
bash脚本myLogger.sh(或者无论你怎么称呼它)。在脚本中,使用以下命令开始日志中的每一行:printf '%(%Y-%m-%d %H:%M:%S)T' -1
Run Code Online (Sandbox Code Playgroud)
printf不会引入换行符,因此您应该能够在此之后立即附加日志数据。
| 归档时间: |
|
| 查看次数: |
1775 次 |
| 最近记录: |