Log-Entry icon indicating copy to clipboard operation
Log-Entry copied to clipboard

Add switch and toggle to log code line number

Open gostega opened this issue 5 years ago • 5 comments

Hi. This is not an issue but a feature request. Hoping to get a switch -linenumber [alias -line] to optionally add the line number to the log. Also, a global toggle to turn logging of line numbers on by default.

Thanks so much for making the effort to write and also publish this amazing tool. I'll try to add this feature myself when I have some time. I can tell you must have put so much time into it, ironing out all the bugs and weird edge cases. I did the same myself with Batch logging back in the day and never had the heart to convert it to powershell so yours is perfect.

gostega avatar Oct 25 '19 10:10 gostega

Getting the line number is done like this: $MyInvocation.ScriptLineNumber

I would use the feature like this:

Log -line "hi"

Result in the logfile should be: 17:52:08.42 Line176 hi

gostega avatar Oct 25 '19 10:10 gostega

Just for reference, I am supporting this in https://github.com/geberit/elastic-helpers/blob/master/logging_examples/logging.ps1

ypid-geberit avatar Oct 25 '19 14:10 ypid-geberit

Thank you for your suggestion. I will take this in consideration.

iRon7 avatar Oct 30 '19 07:10 iRon7

Thank you for your suggestion. I will take this in consideration.

Hi iRon7, I've added the functionality in my fork, and tested as a psm1 module and also in my own code, all seems good. I've created a pull request for you to add if you feel like. I am new to git, and github so apologies if I've breached etiquette or made any mistakes with this pull request.

gostega avatar Oct 30 '19 11:10 gostega

Just for reference, I am supporting this in https://github.com/geberit/elastic-helpers/blob/master/logging_examples/logging.ps1

Thanks, I'll take a look.

gostega avatar Oct 30 '19 11:10 gostega