Skip to main content

Microsoft

Viewing Logs Live in Windows

In the world of app troubleshooting, the app’s logs are your best friend. Sometimes you know when your error is happening, but sometimes you need to know, down to the moment, when the error shows up in the log files. In other words, sometimes you want to view all updates to the log exactly as they happen. If you’re working in Windows and find yourself in this position, here’s a quick rundown of my favorite ways to live-view log files.
I’m using an instance of Sitecore for these examples, but these methods work for viewing all text logs, and not just Sitecore logs.

Method 1: Windows PowerShell

In Windows PowerShell, the basic command to live-view updates to a file is:

Get-Content {MyFile} -Wait -Tail 30

Usage:

cd C:\inetpub\wwwroot\MySitecoreInstance\Data\logs
Get-Content Log.20160706.txt -Wait -Tail 30

In the case of Sitecore, and probably many other solutions, the most-recently-modified file is the active log. Here’s a command I wrote to automatically Get-Content  on the most-recently-modified file (that matches Sitecore’s log.*.txt  pattern) in the directory:

cd C:\inetpub\wwwroot\MySitecoreInstance\Data\logs
gci -Filter log.*.txt | sort LastWriteTime | select -last 1 | Get-Content -Wait -Tail 30

powershell get-content

Watching Sitecore spin up from the log…


The advantage of this method is its availability on any system that has PowerShell installed, and PowerShell is installed by default on systems running Windows 7 and up. A minor drawback, when I’ve run this command on Win7 systems, is a low refresh rate. This appears to have been fixed in Win8 onwards.

Method 2: Baretail.exe

Named after the “tail” command from the Unix/Linux world, Baretail is a free, lightweight, stand-alone executable. Baretail’s one job is to live-view log files, and it also sports some nice features like color-coding. When I have used this app, it has served its purpose quite nicely. Baretail’s inherent drawback is that some systems are going to be more locked down (read: production servers), and that means not running .exe files that you’ve pulled down from the Internet. This is why Method 1 is more common for me; there’s a much better chance that PowerShell will be on a server. It’s also worth mentioning that Baretail hasn’t seen a new version released since 2006, but the app still appears to be compatible with the latest version of Windows 10.

baretail

I’ve told Baretail to highlight lines containing “ERROR”.


I’ve heard Doc Monitor plugin for Notepad++ mentioned as a solution similar to Baretail.exe but I haven’t tried this myself. I assume this will face similar drawbacks: This will only be usable on systems where Notepad++ is installed.

Method 3: The Tail command

This is going to be a rare case, but I’m throwing it in for variety. Suppose you’re working on a system that has Windows Subsystem for Linux*, Cygwin, or something else that provides a Unix-like shell in Windows. If you are part of this edge case, you have the Tail command available, which has been around for decades and is very decent. Similar to the PowerShell command I wrote, using this command** in your shell will pull the current Sitecore log and follow along:

tail -f `ls -t /mnt/c/inetpub/wwwroot/MySitecoreInstance/Data/logs/log.* | head -n1`

Tail running on WSL

Tail running on Windows Subsystem for Linux.


*As of 7/6/16, Windows Subsystem for Linux is still in beta, and only available for Windows 10 users who are part of the Windows Insider program and have enabled Fast Ring updates. Of course, this will change in the future.
**In WSL, the C drive is mapped to /mnt/c/  . In Cygwin, the C drive is mapped to /cygdrive/c/ .

Honorable Mention: Sitecore Log Analyzer

For you Sitecore developers, I have to throw this in because it’s such a valuable tool and I see so many Sitecore devs who don’t even know it exists: the Sitecore Log Analyzer (SCLA). While this doesn’t enable you to view log files live, SCLA provides detailed analysis of log files, making it easy to track error trends, timelines, and more. I consider SCLA an essential tool for Sitecore support.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Jacob King

Jacob King is a Senior Technical Consultant for Perficient, specializing in Sitecore solutions. He lives in Indianapolis with his wife and son.

More from this Author

Categories
Follow Us
TwitterLinkedinFacebookYoutubeInstagram