More goodness added to aaLog; New Options format

Spurred on by a request from a user with a unique situation I have been hard at work adding some new features to the aaLog library.  Over the course of the next few posts I will discuss many of the new features that have been added.  To start things off I’ll give information on the new options format.

New Method for Specifying Options

When you typically start out with a program you typically will pass in options via command line arguments.  Then, over time, this list grows to an uncontrollable monster.  Over the course of my last few projects I have come up with a really nice method for managing this in a much simpler fashion; the options file in JSON format.

Using a combination of an options type

and the Newtonsoft JSON library we can very easily create a single line method that will read in an options file and deserialize it for use in our application. By specifying defaults in the options class you only need to specify non-default options in your options file.

Here is an example of what a simplified options file might look like:

Using this composable options method we can now specify complex items in the options file using JSON.

What’s even better is that you can read in the options file but modify those options before you apply them to the instantiated object.

For a filter you you can approach it in one of two ways. You could specify the filter in the options file or you could just add one in-line after reading in the options file from disk. The example above shows how you might add a new filter in-line. I have compacted the essence of the code into a single line, but here is a simpler version expanded to multiple lines to make it easier to follow along.

Also take note of a couple other nuances.  First, if you are ok with all of the default options then you can just instantiate a new options structure and then add your filters as you go along.  Finally create a new log reader object, passing along the options to the constructor.

Now, you might also want to write these filters into the options file but what happens if you aren’t an expert in JSON.  Simple, create the object and use Visual Studio, use Newtonsoft to extract a JSON file then view it.

Clipboard03

Clipboard04

Taking this text and dropping it into a text file.  There are plenty of JSON beautifiers out there to help you “see” the format better.

In my next post I will discuss more details around Log Filtering.

Leave a Reply