【问题标题】:Timestamps in upstart logs新贵日志中的时间戳
【发布时间】:2013-07-28 17:06:13
【问题描述】:

我在 Ubuntu 上使用 upstart 来管理服务。它写信给/var/log/upstart/<service>.log。此文件中的错误没有时间戳,因此难以诊断问题。

有没有办法——配置文件中的某种节——告诉新贵在其日志输出中写入时间戳?

【问题讨论】:

    标签: logging upstart


    【解决方案1】:

    您可以尝试使用devscripts 包中的annotate-output shell 脚本:

    源码here.

    【讨论】:

      【解决方案2】:

      可能有一种更优雅的方式来做你想做的事,但我发现以下 ghetto 方法足够有效:

                 echo "`date` : Doing the next thing..."
      

      【讨论】:

        【解决方案3】:

        您的服务应保持日期/时间... /var/log/upstart/ 下的日志中出现的日志是你的 upstart 脚本的输出。

        您还可以在 conf 文件中添加 pre-start 和 pre-stop 部分,以打印服务运行前的时间和服务停止后的时间:

        pre-start script
            echo "[`date`] <YOUR SERVICE NAME> Starting" >> /var/log/<YOUR SERVICE NAME>.log
        end script
        
        pre-stop script
            echo "[`date`] <YOUR SERVICE NAME> Stopping" >> /var/log/<YOUR SERVICE NAME>.log
        end script
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2012-09-10
          • 2016-11-06
          • 2015-02-16
          • 1970-01-01
          • 1970-01-01
          • 2015-08-30
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多