What guidelines do you adhere to for writing good logging statements

后端 未结 7 2202
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-24 07:18

I recently found a log statement in my projects codebase that says \"here i am with search parameter==>===========11/30/2008===1====00:00 AM\"

what guidelines do you

7条回答
  •  梦谈多话
    2020-12-24 08:13

    The most useful part in a log statement (except maybe the date & time of course) is a unique ID. All our log entries begin with MSG-xxxxx where xxxxx is a unique integer. This MSG-xxxxx tag is always hard-coded in the source, never in a resource file, so it is easy to find it back. It is also a very easy search key in the documentation.

    Also what is useful is to always enclose variable string content in double quotes to easily differentiate from the message itself:

    MSG-12345 Tried to open "myfile.txt", returned error code "123 - file not found".

    This also helps when you try to extract information from the log using some regular expression.

提交回复
热议问题