Code RoomLogger initialized twice
HardPrep Room Coding #2212

Logger initialized twice

Code reviewConcurrencySenior–Staff~29 min

Review this C++ thread-pool logger using a lazily created singleton.

What a strong answer looks like

Separate real bugs from style. Rank issues by severity, point at the root cause rather than the symptom, and suggest a concrete fix, specific and kind.

0:00 of about 29 min
Mark a line and say what kind of problem it is.0 findings
1class Logger {
2public:
3 static Logger* get() {
4 if (!instance) {
5 instance = new Logger();
6 instance->open("/var/log/app.log");
7 }
8 return instance;
9 }
10 void write(const std::string& s) { out << s << "\n"; }
11private:
12 static Logger* instance;
13 std::ofstream out;
14 void open(const char* p) { out.open(p, std::ios::app); }
15};
16Logger* Logger::instance = nullptr;
Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.