76

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?

23 Answers 23

78

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" }
5
  • 4
    In Notepad++, for those who can't find Document Monitor under the Plugins menu, it can be installed using the Plugin Manager.
    – StormFoo
    Sep 10, 2012 at 14:03
  • Both do not work when file is opened from network :(
    – Mikhail
    May 30, 2014 at 11:43
  • I've found that document monitor only updates after I close the application that's writing to the file I'm trying to monitor.
    – rusty
    Dec 19, 2014 at 20:57
  • Get-Content gives me an error which says "The process cannot access the file because it is being used by another process."
    – rusty
    Dec 19, 2014 at 21:12
  • Currently there doesn't appear to be a Document Monitor plugin, but there is a built-in "Monitoring" option at the bottom of the View menu.
    – Mark
    Sep 11, 2019 at 16:10
36
2
  • haha i remember how we coined the phrase "tailing wget-log" (means waiting for a long download to finish)
    – Midhat
    Sep 24, 2008 at 16:17
  • 3
    as mentioned elsewhere, tail -f is the command. also, if you have git installed, you probably have tail.
    – cregox
    May 18, 2013 at 19:40
19

When using Windows PowerShell you can do the following:

Get-Content someFile.txt -wait
18

I use "tail -f" under cygwin.

2
  • it's in gnuwin32, also: gnuwin32.sourceforge.net/packages/coreutils.htm
    – sm4rk0
    May 26, 2014 at 15:38
  • I didn't have any luck with this; the file I'm trying to tail is getting written to once per second so perhaps it's just always in a locked state. I get "cannot open for reading: Device or resource busy". I'm using tail 8.23 (cygwin package version 8.23-4).
    – rusty
    Dec 19, 2014 at 20:49
16

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.

0
8

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!

1
  • in my PATH. What is my PATH?
    – user4951
    May 7, 2014 at 11:37
6

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.

5

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

1
  • I am really like LOGEXPERT but I cann't work well on Windows10 like it worked on Windows7, I cant open file with sftp
    – vanduc1102
    Jul 14, 2016 at 4:34
4

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.

1
  • This is definitely a hidden gem.
    – Doug
    Jul 28, 2014 at 3:57
3

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

2

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

0
2

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

2
  • 1
    I tested out a few, and even though it's very lightly specced, SnakeTail does 1 thing very well: tail a file with a wildcard pattern. E.g. in Sitecore development, you will have a log file called log.20150901.220158.txtbut on recompile/config change, a new file will be generated with a different timestamp. Setting up SnakeTail with e.g. wildcard-pattern log.*.txt will automatically tail the next file in line, no need to switch targets. Thx for the tip, Erick. Sep 2, 2015 at 7:18
  • You're welcome, dude. Nov 30, 2015 at 16:33
1

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.

1

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

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

1

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

1

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.

1

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

2
  • -1 NullReferenceException - not well tested?
    – Grim
    Aug 22, 2014 at 5:20
  • 1
    seriously a downvote for that? wow, im not selling this - just trying to illustrate how it can be done. Did you put your paths in the config file before running it? Aug 26, 2014 at 11:07
1
@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.

1
  • It worked perfectly for me.
    – 0xAA55
    Nov 5, 2021 at 10:48
0

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.

0

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

0

Tail for Win32

0

I did a tiny viewer by my own:

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

1
  • 1
    Hope it's well tested... ;p Aug 26, 2014 at 11:08

Not the answer you're looking for? Browse other questions tagged or ask your own question.