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.
Bothered by SLOW Web UI to manage vSphere? Want to manage ALL your VMware vCenters, AWS, Azure, Openstack, container behind a SINGLE pane of glass? Want to search, analyze, report, visualize VMs, hosts, networks, datastores, events as easily as Google the Web? Find out more about vSearch 3.0: the search engine for all your private and public clouds.
$ 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. ()