What to write into log file?

2019-02-02 18:37发布

My question is simple: what to write into a log. Are there any conventions? What do I have to put in?

Since my app has to be released, I'd like to have friendly logs, which could be read by most people without asking what it is.

I already have some ideas, like a timestamp, a unique identifier for each function/method, etc.. I'd like to have several log levels, like tracing/debugging, informations, errors/warnings.

Do you use some pre-formatted log resources?

Thank you

7条回答
乱世女痞
2楼-- · 2019-02-02 19:38

In my opinion, best approach is to use existing logging libraries such as log4j (or it's variations for other languages). It gives you control on how your messages are formatted and you can change it without ever touching your code. It follows best practices, robust and used by millions of users. Of course, you can write you own logging framework, but that would be very odd thing to do, unless you need something very specific. In any case, walk though their documentation and see how log statements are presented there.

Check out log4py - Python ported version of log4j, I think there are several implementations for Python out there..

查看更多
登录 后发表回答