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?

Community
  • 1
  • 1
pbreault
  • 14,176
  • 18
  • 45
  • 38

23 Answers23

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" }
Mike Schall
  • 5,829
  • 4
  • 41
  • 47
  • 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 '12 at 14:03
  • Both do not work when file is opened from network :( – Mikhail May 30 '14 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 '14 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 '14 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 '19 at 16:10
36
Jon Galloway
  • 52,327
  • 25
  • 125
  • 193
  • haha i remember how we coined the phrase "tailing wget-log" (means waiting for a long download to finish) – Midhat Sep 24 '08 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 '13 at 19:40
19

When using Windows PowerShell you can do the following:

Get-Content someFile.txt -wait
Lars Truijens
  • 42,837
  • 6
  • 126
  • 143
18

I use "tail -f" under cygwin.

CHitchcock
  • 221
  • 2
  • 4
  • it's in gnuwin32, also: http://gnuwin32.sourceforge.net/packages/coreutils.htm – sm4rk0 May 26 '14 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 '14 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.

John Topley
  • 113,588
  • 46
  • 195
  • 237
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!

Gryu
  • 2,102
  • 2
  • 16
  • 29
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.

ZombieSheep
  • 29,603
  • 12
  • 67
  • 114
5

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

Ragav
  • 942
  • 4
  • 19
  • 37
  • 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 '16 at 04: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.

tiho
  • 6,655
  • 3
  • 31
  • 31
Contango
  • 76,540
  • 58
  • 260
  • 305
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 ;)

Rob Cooper
  • 28,567
  • 26
  • 103
  • 142
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

Nelson Miranda
  • 5,484
  • 5
  • 33
  • 54
2

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

Erick Alves
  • 354
  • 1
  • 4
  • 10
  • 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.txt`but 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. – Frederik Struck-Schøning Sep 02 '15 at 07:18
  • You're welcome, dude. – Erick Alves Nov 30 '15 at 16:33
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.

Shawn Chin
  • 84,080
  • 19
  • 162
  • 191
Simon
  • 11
  • 1
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

mandrake
  • 1,213
  • 1
  • 14
  • 28
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.

Dillie-O
  • 29,277
  • 14
  • 101
  • 140
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

managedheap84
  • 841
  • 2
  • 10
  • 22
  • -1 NullReferenceException - not well tested? – Grim Aug 22 '14 at 05: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? – managedheap84 Aug 26 '14 at 11:07
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.

ryan
  • 5,039
  • 13
  • 35
  • 42
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.

Rob Thomas
  • 686
  • 7
  • 17
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.

Chaitanya
  • 41
  • 3
0

Tail for Win32

Charley Rathkopf
  • 4,720
  • 7
  • 38
  • 57
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.

Lars Truijens
  • 42,837
  • 6
  • 126
  • 143
0

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

Owen
  • 22,247
  • 13
  • 42
  • 47
0

I did a tiny viewer by my own:

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

Grim
  • 1,938
  • 10
  • 56
  • 123