How to monitor a text file in realtime

MonitoringText Files

Monitoring Problem Overview


For debugging purposes in a somewhat closed system, I have to output text to a file.

Does anyone know of a tool that runs on windows (console based or not) that detects changes to a file and outputs them in real-time?

Monitoring Solutions


Solution 1 - Monitoring

I like tools that will perform more than one task, Notepad++ is a great notepad replacement and has a Document Monitor plugin (installs with standard msi) that works great. It also is portable so you can have it on a thumb drive for use anywhere.

For a command line option, PowerShell (which is really a new command line) has a great feature already mentioned.

Get-Content someFile.txt -wait

But you can also filter at the command line using a regular expression

Get-Content web.log -wait | where { $_ -match "ERROR" }

Solution 2 - Monitoring

Solution 3 - Monitoring

When using Windows PowerShell you can do the following:

Get-Content someFile.txt -wait

Solution 4 - Monitoring

I use "tail -f" under cygwin.

Solution 5 - Monitoring

I use BareTail for doing this on Windows. It's free and has some nice features, such as tabs for tailing multiple files and configurable highlighting.

Solution 6 - Monitoring

Tail is the best answer so far.

If you don't use Windows, you probably already have tail.

If you do use Windows, you can get a whole slew of Unix command line tools from here. Unzip them and put them somewhere in your PATH.

Then just do this at the command prompt from the same folder your log file is in:

tail -n 50 -f whatever.log

This will show you the last 50 lines of the file and will update as the file updates.

You can combine grep with tail with great results - something like this:

tail -n 50 -f whatever.log | grep Error

gives you just lines with "Error" in it.

Good luck!

Solution 7 - Monitoring

FileSystemWatcher works a treat, although you do have to be a little careful about duplicate events firing - 1st link from Google - but bearing that in mind can produce great results.

Solution 8 - Monitoring

Late answer, though might be helpful for someone -- LOGEXPERT seems to be interesting tail utility for windows.

Solution 9 - Monitoring

Try SMSTrace from Microsoft (now called CMTrace, and directly available in the Start Menu on some versions of Windows)

Its a brilliant GUI tool that monitors updates to any text file in real time, even if its locked for writing by another file.

Don't be fooled by the description, its capable of monitoring any file, including .txt, .log or .csv.

Its ability to monitor locked files is extremely useful, and is one of the reasons why this utility shines.

One of the nicest features is line coloring. If it sees the word "ERROR", the line becomes red. If it sees the word "WARN", the line becomes yellow. This makes the logs a lot easier to follow.

Solution 10 - Monitoring

I have used FileSystemWatcher for monitoring of text files for a component I recently built. There may be better options (I never found anything in my limited research) but that seemed to do the trick nicely :)

Crap, my bad, you're actually after a tool to do it all for you..

Well if you get unlucky and want to roll your own ;)

Solution 11 - Monitoring

Snake Tail. It is a good option. http://snakenest.com/snaketail/

Solution 12 - Monitoring

Yor can use the FileSystemWatcher in System.Diagnostics.

From MSDN:

public class Watcher {

public static void Main()
{
Run();

}

[PermissionSet(SecurityAction.Demand, Name="FullTrust")]
public static void Run()
{
    string[] args = System.Environment.GetCommandLineArgs();

    // If a directory is not specified, exit program.
    if(args.Length != 2)
    {
        // Display the proper way to call the program.
        Console.WriteLine("Usage: Watcher.exe (directory)");
        return;
    }

    // Create a new FileSystemWatcher and set its properties.
    FileSystemWatcher watcher = new FileSystemWatcher();
    watcher.Path = args[1];
    /* Watch for changes in LastAccess and LastWrite times, and 
       the renaming of files or directories. */
    watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite 
       | NotifyFilters.FileName | NotifyFilters.DirectoryName;
    // Only watch text files.
    watcher.Filter = "*.txt";

    // Add event handlers.
    watcher.Changed += new FileSystemEventHandler(OnChanged);
    watcher.Created += new FileSystemEventHandler(OnChanged);
    watcher.Deleted += new FileSystemEventHandler(OnChanged);
    watcher.Renamed += new RenamedEventHandler(OnRenamed);

    // Begin watching.
    watcher.EnableRaisingEvents = true;

    // Wait for the user to quit the program.
    Console.WriteLine("Press \'q\' to quit the sample.");
    while(Console.Read()!='q');
}

// Define the event handlers.
private static void OnChanged(object source, FileSystemEventArgs e)
{
    // Specify what is done when a file is changed, created, or deleted.
   Console.WriteLine("File: " +  e.FullPath + " " + e.ChangeType);
}

private static void OnRenamed(object source, RenamedEventArgs e)
{
    // Specify what is done when a file is renamed.
    Console.WriteLine("File: {0} renamed to {1}", e.OldFullPath, e.FullPath);
}

}

You can also follow this link Watching Folder Activity in VB.NET

Solution 13 - Monitoring

Just a shameless plug to tail onto the answer, but I have a free web based app called Hacksaw used for viewing log4net files. I've put in an auto refresh options so you can give yourself near real time updates without having to refresh the browser all the time.

Solution 14 - Monitoring

Yeah I've used both Tail for Win32 and tail on Cygwin. I've found both to be excellent, although I prefer Cygwin slightly as I'm able to tail files over the internet efficiently without crashes (Tail for Win32 has crashed on me in some instances).

So basically, I would use tail on Cygwin and redirect the output to a file on my local machine. I would then have this file open in Vim and reload (:e) it when required.

Solution 15 - Monitoring

+1 for BareTail. I actually use BareTailPro, which provides real-time filtering on the tail with basic search strings or search strings using regex.

Solution 16 - Monitoring

To make the list complete here's a link to the GNU WIN32 ports of many useful tools (amongst them is tail). GNUWin32 CoreUtils

Solution 17 - Monitoring

Surprised no one has mentioned Trace32 (or Trace64). These are great (free) Microsoft utilities that give a nice GUI and highlight any errors, etc. It also has filtering and sounds like exactly what you need.

Solution 18 - Monitoring

Here's a utility I wrote to do just that:

It uses a FileSystemWatcher to look for changes in log files within local folders or network shares (don't have to be mounted, just provide the UNC path) and appends the new content to the console.

on github: https://github.com/danbyrne84/multitail

http://www.danielbyrne.net/projects/multitail

Hope this helps

Solution 19 - Monitoring

@echo off

set LoggingFile=C:\foo.txt
set lineNr=0

:while1
for /f "usebackq delims=" %%i in (`more +%lineNr% %LoggingFile%`) DO (
    echo %%i
    set /a lineNr+=1
    REM Have an appropriate stop condition here by checking i
)
goto :while1

A command prompt way of doing it.

Solution 20 - Monitoring

FileMon is a free stand alone tool that can detect all kinds of file access. You can filter out any unwanted. It does not show you the data that has actually changed though.

Solution 21 - Monitoring

I second "tail -f" in cygwin. I assume that Tail for Win32 will accomplish the same thing.

Solution 22 - Monitoring

Solution 23 - Monitoring

I did a tiny viewer by my own:

https://github.com/enexusde/Delphi/wiki/TinyLog

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionpbreaultView Question on Stackoverflow
Solution 1 - MonitoringMike SchallView Answer on Stackoverflow
Solution 2 - MonitoringJon GallowayView Answer on Stackoverflow
Solution 3 - MonitoringLars TruijensView Answer on Stackoverflow
Solution 4 - MonitoringCHitchcockView Answer on Stackoverflow
Solution 5 - MonitoringJohn TopleyView Answer on Stackoverflow
Solution 6 - MonitoringAdamView Answer on Stackoverflow
Solution 7 - MonitoringZombieSheepView Answer on Stackoverflow
Solution 8 - MonitoringRagavView Answer on Stackoverflow
Solution 9 - MonitoringContangoView Answer on Stackoverflow
Solution 10 - MonitoringRob CooperView Answer on Stackoverflow
Solution 11 - MonitoringErick AlvesView Answer on Stackoverflow
Solution 12 - MonitoringNelson MirandaView Answer on Stackoverflow
Solution 13 - MonitoringDillie-OView Answer on Stackoverflow
Solution 14 - MonitoringryanView Answer on Stackoverflow
Solution 15 - MonitoringRob ThomasView Answer on Stackoverflow
Solution 16 - MonitoringmandrakeView Answer on Stackoverflow
Solution 17 - MonitoringSimonView Answer on Stackoverflow
Solution 18 - Monitoringmanagedheap84View Answer on Stackoverflow
Solution 19 - MonitoringChaitanyaView Answer on Stackoverflow
Solution 20 - MonitoringLars TruijensView Answer on Stackoverflow
Solution 21 - MonitoringOwenView Answer on Stackoverflow
Solution 22 - MonitoringCharley RathkopfView Answer on Stackoverflow
Solution 23 - MonitoringGrimView Answer on Stackoverflow