// Case 1 // BAD - no flushing; will yield an assertion get_log().ts() << "message"; // Case 2 // ok – flushing prior to destruction get_log().ts() << "message" << std::endl; // Case 3 // ok - one flush, prior to temp's destruction { thread_safe_log temp = get_log(); for ( int idx = 0; idx < 100; ++idx) temp.ts() << "message [" << idx << "]\n"; temp.ts() << std::endl; } // Case 4 // BAD - no flushing; will yield an assertion { thread_safe_log temp = get_log(); for ( int idx = 0; idx < 100; ++idx) temp.ts() << "message [" << idx << "]\n"; } // Case 5 // ok – 100 flushes { thread_safe_log temp = get_log(); for ( int idx = 0; idx < 100; ++idx) temp.ts() << "message [" << idx << std::endl; // no need to flush() here; each message has been flushed inside the 'for' } |