Listing I
Changing from internal_thread_safe_log_ownthread
to internal_thread_safe_log_sharethread
 
 
The code:
 
 
thread_safe_log get_log()
{
    static std::ofstream out( "out.txt" );
    static internal_thread_safe_log_ownthread log( out);
    return thread_safe_log( log);
}
 
 
Needs to be changed into:
 
 
// now, we need a reference to a thread-safe log writer,
// so that multiple logs can share it
thread_safe_log_writer_sharethread & get_ts_writer()
{
    static thread_safe_log_writer_sharethread writer;
    return writer;
}
 
 
 
 
thread_safe_log get_app_log()
{
    static std::ofstream out( "out.txt" );
    static internal_thread_safe_log_sharedthread log( out, get_ts_writer(), 15 /* priority */);
    return thread_safe_log( log);
}
 
 
// say we have an errors log as well
thread_safe_log get_err_log()
{
    static std::ofstream out( "err.txt" );
    static internal_thread_safe_log_sharedthread log( out, get_ts_writer(), 20 /* priority */);
    return thread_safe_log( log);
}
 
 
 
Changing from internal_thread_safe_log_sharethread
to internal_thread_safe_log_ownthread
 
 
The code:
 
 
thread_safe_log_writer_sharethread & get_ts_writer()
{
    static thread_safe_log_writer_sharethread writer;
    return writer;
}
 
 
thread_safe_log get_app_log()
{
    static std::ofstream out( "out.txt" );
    static internal_thread_safe_log_sharedthread log( out, get_ts_writer(), 15 /* priority */);
    return thread_safe_log( log);
}
 
 
Needs to be changed into:
 
 
// note: the get_ts_writer() is not needed for the get_app_log();
// it might, however, be needed by ***other*** logs
 
 
thread_safe_log get_app_log()
{
    static std::ofstream out( "out.txt" );
    static internal_thread_safe_log_ownthread log( out);
    return thread_safe_log( log);
}