How do you make sure your logs are sufficient? [closed]

I was in a job interview with a vp r&d today.

One of his questions went something like:

“How do you make sure your code works?”

This question struck me as a bit strange, so I explained how I debug (divide and conquer, debugger, prints, unit testing).

He then continued:

“What if the problem only comes once a day?”

I said I would use a log.

He then asked

“What would you put in the log?”

“How can you make sure that when you get the log, you would be able to find the problem quickly?”

I sat there quietly, not knowing the answer he was looking for.

The question seems over-broad to me, and I am sure with some specific context I would have been able to come up with something.

Maybe it’s actually a viable question and I just have a knowledge gap, or I just don’t get something…

My question to you:

Is there any standard methodology for logging?

What answer could he have been waiting to hear?

16

How do you make sure your logs are sufficient?

My 11th grade English teacher has the best answer for this question:

Know your audience.

Think about who will be reading this. What they will and wont know. Think about what they need.

When you log, log with intention. There should be a point to everything you capture. You should be thinking about the use cases your logs will be put to. You should have clear ideas here. Otherwise you give up and just log everything.

To much logging is worse than not enough. I’ve been on teams that couldn’t control this and created beasts that filled up our largest hard drives every few days. Worse the torrent of data kept normal users from being able to figure out what was happening to the system.

When you log think about who you’re logging for. They are your audience. Do not overwhelm them. Keep what you show them clear, brief and useful.

Conversely, insufficient logging is easy to fix. Add logging as you find you need it. This only works though if you are iteratively developing. That is, you write it, use it, learn from it, and rewrite it. Some people just call this testing.

For that to work you have to put yourself in the mind of who will use the log. This can be end users as well as maintenance programmers. Your log might inspire searches of the code base. It might inspire searches on google. Give them enough keywords that they can find appropriate results.

Also, it can be useful to know the state of the system. Sure give me a break point and a reproduceable error and I can learn that myself but I still hate seeing “File not found” with no mention of the expected file name. Give me the fully qualified name and I’ll know where to put the file to fix this problem.

“How can you make sure that when you get the log, you would be able to find the problem quickly?”

Make sure you log something that can be used in a search. You don’t have to dump a full stack trace for every log entry. Not everything you log is consumed by a programmer anyway. But what you log should be something someone could look up in something.

When logging an error, a stack trace might be appropriate but logging covers more than errors. Class and method name are sometimes enough, usually right next to the date-time stamp. Even without those you can still provide a way to find what created this log entry by ensuring use of a unique word or phrase that can be found by searching the code base. I’ve used this one plenty.

Pro tip: don’t break up the searchable phrase by word wrapping it in the source code. People aren’t going to know where to put "n + " in their search string.

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật