Debug Levels when writing an application

前端 未结 8 1321
别那么骄傲
别那么骄傲 2020-12-23 12:11

I would like to know if you guys have any suggestions about debug levels when writing an application.

I thought about 4 levels:

0 : No Debug
1 : All inpu

8条回答
  •  情话喂你
    2020-12-23 12:43

    0: no logging

    1: exception logging: log every thrown error. For example in c#: logging in catch blocks. When these log operations are triggered, you know you have an error. You can also log in switch statements if there is a case which should never be hit and the like.

    2: operation logging: logging operations, which are not in catch blocks (normal operations), should be set to high debugging. This way you can see which method starts executing and then ends up in a catch block.

    Also, think about logging switches, for example packet logging (true: log network packets/messages, false: don't). Just don't overdo with switches.

    At exception handling, every method body should be at least in a try-catch block, at least with a general Exception catch at the end. Put logging in the catch block, add optional information besides the system message and the stack trace to indicate what caused the error, then throw the error. Stop throwing errors further only when the user has been notified about the error, or you are at the top level of an application, which has no active user interface. (Server side logging for example.) Then you need to indicate in a message to the client app that an error has happened server side.

提交回复
热议问题