Foolproof logFileName

So your PowerShell skills are coming along nicely and you started generating output!

One of the things you’ll run into sooner or later (more sooner than you think) is the vast amount of output data and how to distinguish which script generated what output when and at times even with which input source.

So before I tell you how I’ll give you little nugget to ponder on.

“Data + Meta Data = Information”

This little gem I picked up a while back reading about data security. There was an interesting chapter about external meta data and internal meta data. My takeaway from that chapter was this,  There is value in adding some metadata to give you that edge. When saving data, save it in such a way you can quickly discern what it’s all about!

I’ve had some periods that i’ll quickly glance at the size of the file to see if I should open it or not. My rule of thumb is, if the file is less than 6 KB it’s probably a test. If it’s bigger than say 100 KB then it may have the info I’m looking for. But what happens if you want or need to revise some time later on? Will you still remember how you produced said data?

Enter  foolproof logFileName.

Whenever I need to export data I’ll use the following format: “date”_”InputFile”_”ScriptName”

Using this format tells me:

  • When I produced the file
  • Which input file I used to generate the data. That comes in handy if you ever need to reproduce something in the future.
  • Which script I used to generate the data for this file. I’ve had times I couldn’t remember which script produced this output

So that’s the why, here’s the how:

$LogDate = get-date -uformat "%Y-%m-%d"
$csvFile = "Temp.csv"
$ScriptName = $MyInvocation.MyCommand.Name

$LogFile = "$($LogDate)_$(($csvFile).TrimEnd('.csv'))_$(($ScriptName).TrimEnd('.ps1')).csv"
$LogFile

If you copy & paste and save the script (I named it Create-LogFileName.ps1… How original is that eh?) you’ll get a string like this: 2014-07-20_Temp_Create-LogFileName.csv

I generally use underscore as a separator in FileNames. Like I said, csv is my goto format so I preformatted it this way.

Well that my tip for generating foolproof log file names to quickly discern what the content is all about.

Hope it’s worth something to you…

Ttyl,

Urv

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s