Do You Speak LogFile?

Thursday, April 4, 2019 4:25 PM umbraco

If you are using Umbraco v8, you probably have noticed that the beautiful text logfiles containing lines as explicit and helpful as

2019-04-04 10:31:35,309 [P3248/D10/T5] INFO Umbraco.Core.Logging.OwinLogger - [Information] Event Id: 0, State: Login attempt failed for username from IP address ::1

have turned into the following uber-geekish gibberish

{"@t":"2019-04-04T10:31:35.3099502Z","@mt":"[{EventType}] Event Id: {EventId}, State: {State}","EventType":"Information","EventId":0,"State":"Login attempt failed for username from IP address ::1","SourceContext":"Umbraco.Core.Logging.OwinLogger","ProcessId":3248,"ProcessName":"iisexpress","ThreadId":5,"AppDomainId":10,"AppDomainAppId":"LMW3SVC2ROOT","MachineName":"DESKTOP-BPQ57JN","Log4NetLevel":"INFO ","HttpRequestNumber":3,"HttpRequestId":"0aa853af-825e-4f4a-990b-2744dc37899a"}

and that is... a Good Thing! Indeed, these Json log files can easily be parsed by the new, shiny, built-in log viewer in the Settings section—or by any tool that you would want to use to parse log files.


The drawback is that these files are simply impossible to read outside of the log viewer.

For instance, if you send your logfile to friends with the vain hope that they could be able to figure out why nothing works on your production site... they may try to feed it to some Json-formatting tool but even then... it is pretty useless.

And no, Google Translate does not speak logfile yet.

But, do not despair! There is a way! Read this blog post and get this tool named CLEF and use it to convert the Json file to the text version. I do it from the Git Bash shell and have created the following alias:

alias clef='/c/Program\ Files/CLEF\ Tool/clef.exe --format-template="{Timestamp:yyyy-MM-dd HH:mm:ss,fff} [P{ProcessId}/D{AppDomainId}/T{ThreadId}] {Log4NetLevel}  {SourceContext} - {Message:lj}{NewLine}{Exception}" -i'

Which I use as

clef useless.json > beautiful.txt

You would have to adapt it to your favorite shell (e.g. PowerShell...), of course, because nothing is free in this world, but that should be an easy task, and then you would be speaking logfile like a native.

You're welcome.

comments powered by Disqus