Hacker News new | past | comments | ask | show | jobs | submit login

"%(asctime)s - %(levelname)-5s - %(name)-20.20s - %(message)s - (%(filename)s:%(lineno)s)"

Here’s a logging format that I use and probably you should too. Among other things, it gets around most of the context issues by outputting the file and line number of the code that called the log.

Before I would try and make every log message unique or mostly unique so there weren’t double ups.

I don’t agree with the authors logging clutter though. If you’re manually eyeballing the logs looking for a message you’re already doing it wrong. Use search, have ids in the messages etc.

Remember folks, debug logging on because if it’s not logged, when it breaks you don’t have the logs…




This is the way.

You should be able to immediately tell from looking at any log entry:

* When it happened

* How serious it is (Informational, Warning, Error, Fatal - at a minimum)

* Type of issue (ideally a unique issue type from a list of known issue types)

* Who logged it (system / subsystem / module / line number)

* What happened (including any germane variable values)


If I can't query for warning level on journalctl it's useless.


That would be the levelname part. But if your log aggregator or subsystem is hindering your ability to use your logs, I would look to solve that problem before worrying about anything within your application.

Even storing logs in a format that you need to decode or download would be a red flag for me. Seconds of debugging all of a sudden turns into minutes or even hours.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: