Low-overhead Multi-file Tail plugin for Rainmeter

Low-overhead Multi-file Tail plugin for Rainmeter

Low-overhead Multi-file Tail plugin for Rainmeter

I’ve always thought the computer interfaces in movies were cool.  Unrealistic, impractical, but cool.  I especially liked the interfaces where there were multiple windows of scrolling text – and I thought  this could actually be useful in real life.

At work I use several services (mostly JADE databases) that log their status to files, and it would be useful to be able to see the current contents of the log files.  I thought an interface like one from the movies could be useful for this – one where there are several windows on the desktop that contain automatically updating displays of the most recently added lines (known as the “tail”) of the log files.

I tried writing a program to do this.  The first hurdle was putting a transparent window on the desktop, and I fell at the first hurdle.  Putting a window on the desktop used to be pretty easy, but Microsoft changed things in Vista, and it became almost impossible to do.  Apparently they thought that enthusiasts’ desktop customization needs would be met by their Sidebar gadgets feature, so nobody would need to put windows on the desktop anymore.

Separately from that effort, Rainmeter v2 was released.  Rainmeter is a piece of desktop customization software that’s been around for a long time, but the important thing in this context is that it can put a window on the desktop.  There is a Tail plugin for Rainmeter, but it doesn’t do exactly what I want – it only works with a specific filename and loads the whole file on every update, so it’s not very efficient for big log files, frequent updates or over a network.  I wanted to write my own tail plugin for Rainmeter, but I don’t have a lot of experience with writing C++.  Fortunately in v2, Rainmeter added the ability to write C# plugins.  I don’t have much experience in C# either, but it’s closer to languages I’m used to and means I can leverage .Net framework classes.

Loading a file is easy, but the goals for my plugin were “low-overhead” and “multi-file”.  What I mean by “low-overhead” is reading as little of the log file as necessary as infrequently as possible.  I ran into a few dead ends because the documentation for C# Rainmeter plugins are basically non-existent, but eventually I achieved this goal by storing the last updated timestamp of the log file and caching the last text I read from it.  This way Rainmeter can update the plugin as often as it wants, but the log file will only be read if it was modified since the last refresh.  The plugin also only reads the last few KB of the log file, so that no matter how big the log file is we aren’t causing a lot of disk I/O or network traffic.

Many applications automatically roll-over their log files in order to avoid having one huge file that just gets bigger and bigger and can’t be deleted because it’s always in use.  Sometimes they just sequentially number the files, for example when log1.log reaches the maximum allowed size, log2.log is started.  Other times log files are date stamped, so there’s only ever one log file per day.  In any case, the purpose of the “multi-file” goal was to automatically read from the latest log file.  This is achieved by specifying a file mask (like c:\log*.log) instead of a specific filename (like c:\log1.log).

EDIT: The developers of Rainmeter drastically changed their plugin framework so my plugin stopped working.  I’ve finally had time to rewrite the plugin using the new framework.  The bad news is that it’ll only work in Rainmeter v2.3 and later.  The good news is that the new framework is better, so I’ve been able to employ mechanisms to reduce the resource usage even further!  So here it is – my new and improved Low-overhead Multi-file Tail plugin for Rainmeter.  Use it in good health.

Enhanced by Zemanta