How To Monitor Log File in Real Time and Save New Log To Another File
During software development, we often add lots of logs that help debug and trace the code. When the log files grow bigger, it gets harder to locate the right information of interest. Even we restart the application, the old log remains and new info appends the end of the file unless we delete log file. It’s OK to delete a log file but it’s better to keep it in case for information of previous runs. Here is a trick that I use to make it easier for me to find right log of interest, and it may help you as well.
Let’s first take a look how it works. Assume you have a log file called doublecloud.log, and your application continuously writes to it. When you are ready to try out something, you can run the following command to monitor it in real time on terminal.
Time to learn how to "Google" and manage your VMware and clouds in a fast and secureHTML5 App
$ tail -f doublecloud.log
It works fine when the information is limited; otherwise it can easily fill several screens and make it hard to find information. In the later case, we can save the real-time into another file as follows:
$ tail -f doublecloud.log | tee firstrun.txt
Now you continue to see the real-time log on the terminal, and it’s also saved to another file called firstrun.txt. You can always open it and take a closer look later. In this way, I can precisely save the part of the real-time log during the window of time. Sometimes I type in the command, start GUI interaction with the system, and at last close the command. After that, all the logs during that period is captured in another file. It makes life much easier especially when the log time is a bit skewed.
So this trick works only on Linux. On Windows, you may want to use wintee or other options as discussed at StackOverflow. ()