我有一个我无法修改的程序,它被硬编码写入位于/tmp/myprogram.log
的日志文件。
我需要能够在不同的用户在同一台服务器上运行该程序的多个副本。 所以我需要将日志文件分离出来。
我试着把/tmp/myprogram.log
一个指向~/myprogram.log
的符号链接,认为这意味着程序会把日志写到用户程序运行的用户目录中,但不幸的是它是shell这扩大了~
所以不起作用。
我会考虑为您的程序获取源代码并进行更改。 我会是一个class轮。 你甚至可以在这里张贴这一行,我们可以帮助改变它。
别人build议的chroot也会起作用。
这个说到欺骗你的程序写一个不同的文件…我无法得到它的编译,但想法和讨论在那里。
https://unix.stackexchange.com/questions/211394/redirect-a-file-descriptor-before-execution
如果你发布的日志logging的人可以帮助这里的代码。
因为如果它是使用logging器,你可以通过指定的参数来configuration文件或一些应用程序的名称,基本上有一些名称将为这些多个实例做不同的名称。
下一步将使用此string标记logging器,并将其转发到像“local4”这样的自定义通道。 对于testing,你可以通过调用命令logger -p local4.info -t "YourTAG" "Log message"
为了完成设置:syslogtag,contains,"<YourTAG>" -/path/to/name1.log & stop :syslogtag,contains,"<AnotherTAG>" -/path/to/name2.log & stop . local4.* -/path/to/some.log # This will catch all tags which would't be mentioned before. & stop
来捕获/etc/rsyslog.d/your.conf
那些标签:syslogtag,contains,"<YourTAG>" -/path/to/name1.log & stop :syslogtag,contains,"<AnotherTAG>" -/path/to/name2.log & stop . local4.* -/path/to/some.log # This will catch all tags which would't be mentioned before. & stop
:syslogtag,contains,"<YourTAG>" -/path/to/name1.log & stop :syslogtag,contains,"<AnotherTAG>" -/path/to/name2.log & stop . local4.* -/path/to/some.log # This will catch all tags which would't be mentioned before. & stop