tail命令以非实时方式显示日志文件内容 [英] tail command showing log file contents in non-real time

查看:265
本文介绍了tail命令以非实时方式显示日志文件内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个C ++应用程序(在Solaris 10上),该应用程序显示基于时间顺序事务的日志输出.例如,在建立与数据库服务器的连接之前,它将在stdout中打印为:"Connecting to DB",并且在连接调用之后,如果成功,则显示"Connected to DB";如果失败,则显示未能连接到DB". "等等. 现在,在运行应用程序时,输出(stdout)将被重定向到如下所示的日志文件:

I have a C++ application (on Solaris 10) that shows log output based on the time chronological transactions. For example, before establishing a connection to Database server, it prints in stdout as: "Connecting to DB" and after the call to connect, if successful, says "Connected to DB", if failed, says, "failed to connect to DB" and so on. Now, when the application is run, the output (stdout) gets redirected to a log file as below:

appl > app.log

在另一个会话中,要查看发生了什么,我将其查看为:

And, on another session, to see what's going on, I view as:

tail -f app.log

tail -f命令应该以无限循环的方式运行,休眠一秒钟,然后尝试从app.log中读取和复制行并在控制台上显示.这有助于监视app.log中发生的情况 当我看到输出的顺序保持不变时,我看到有时输出将很多行作为一个块放在一起,然后等待,这并不是实时发生的.是因为尾巴-f的睡眠和牵引行为吗?请帮助我了解为什么它不是实时的.还是有其他方法可以让您感受到实时感?

tail -f command is supposed to run in an endless loop, sleeping for a second and then attempt to read and copy lines from app.log and show on console. This helps to monitor what's going on in app.log While I see the ordering of outputs maintained, I see that sometimes outputs are coming many lines together as a chunk and then waiting, and it's not in real-time as things are happening. Is it because of the sleep and pull behavior of tail -f? Please help me to understand why it is not in real time. Or is there any other way to get a feel of real time?

推荐答案

尝试在此文件上使用watch命令,间隔为5秒,并查看其行为是否与tail相同.如果实时缺少对文件app.log的写入,则将在尾部显示类似的结果.

Try using the watch command on this file with an interval of 5 seconds and see if its having the same behavior as tail. If the write to the file app.log is missing in real-time similar will be the output in tail.

这篇关于tail命令以非实时方式显示日志文件内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆