Question

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?

Was it helpful?

Solution

OTHER TIPS

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" }

I use "tail -f" under cygwin.

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.

When using Windows PowerShell you can do the following:

Get-Content someFile.txt -wait

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.

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: http://unxutils.sourceforge.net/ - 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!

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

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 ;)

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.

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

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

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.

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.

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

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

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.

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

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.

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

I did a tiny viewer by my own:

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

@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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top