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.

Lost VMs or Containers? Too Many Consoles? Too Slow GUI? Time to learn how to "Google" and manage your VMware and clouds in a fast and secure HTML5 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. ()

This entry was posted in Applications & Tools and tagged , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Post a Comment

Your email is never published nor shared. Required fields are marked *


You may use these HTML tags and attributes <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>


    My company has created products like vSearch ("Super vCenter"), vijavaNG APIs, EAM APIs, ICE tool. We also help clients with virtualization and cloud computing on customized development, training. Should you, or someone you know, need these products and services, please feel free to contact me: steve __AT__

    Me: Steve Jin, VMware vExpert who authored the VMware VI and vSphere SDK by Prentice Hall, and created the de factor open source vSphere Java API while working at VMware engineering. Companies like Cisco, EMC, NetApp, HP, Dell, VMware, are among the users of the API and other tools I developed for their products, internal IT orchestration, and test automation.