4

Do you know a set of guidelines for writing into a log file?

The file can be long, it should contain a log message per line, including dates and system feedback / audit actions. I may contain user names, status messages, ERRORs, references to files or applications, etc. Each line should not be so long, but there could be exceptions. We cannot use colors, font formatting (like bold or italic) or GUI.

The purpose is to make it more readable and to help the reader to visually scan and find important information easily.


Hint: the user may be a system admin / technical user and it's on Linux environment. Information about well-known characters and words is also valid.

2

One important thing about plaintext formatting is lining up columns. If you have values of a predictable maximum size like numbers that will never be more than 9 digits, or dates and times you should pad with extra space so they are inside a column of uniform width to aid visual scanning.

Currency values usually hav a standard .00 at the end and is right aligned in it's column.

Consider using commas to separate thousands if you know the locale of your audience. European countries flip the meaning of commas and periods in number formatting sometimes.

Put the columns with fixed widths to the front and those with variable widths at the end. Then sort by importance to the audience, (usually someone that is trying to troubleshoot a problem).

Put dates in the standard order of increasing granularity "2017-03-01" that way it sorts visually.

Using Pipe characters to delimit fields should be considered unless there is a pressing need for a more standard delimiter such as a comma.

Add visual padding using spaces around each delimiter

Avoid visual clutter such as string quotes around values.

Consider using emoji if you think this will be in a Unicode text buffer. But don't go overboard with the emoji. A restrained vocabulary is best since meanings are so subjective, and subjectivity is usually not desirable in a log file.

Here's my mockup:

| 2017-03-01 |    12.33 | 192.168.1.1     | Foo       | Bar.bat.alice.bob.variablelengthstrings | lorem ipsum dolor sit amet something something
| 2017-03-02 |   824.01 | 192.168.13.22   | FooBarBat | bob.variablelengthstrings | lorem ipsum something
| 2017-03-02 | 1,223.11 | 192.168.119.101 | Foo       | variablelengthstrings | lorem ipsum dolor sit amet another thing that goes long something something

Do a technical test run of whatever you come up with by importing a sample log file into Excel and see what happens.

  • You've captured valuable concepts here. Thanks. It's important to notice that we can't always sort the results, specially for real-time logging. – Ricardo Mar 3 '17 at 18:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.