ACE日志输出的重定向

ACE日志默认输出在stderr上,这对于非CUI程序来说基本无用.还好ACE提供了重定向功能

1.重定向到指定的文件:

     ACE_OSTREAM_TYPE *pOutput = new ofstream ("log.txt");   
     ACE_LOG_MSG
->msg_ostream ( pOutput,  1 ); //第二个参数指定为1, 那么pOutput的删除工作由ACE完成   
     ACE_LOG_MSG->set_flags (ACE_Log_Msg::OSTREAM);    
     ACE_LOG_MSG
->clr_flags (ACE_Log_Msg::STDERR);

2.重定向到回调函数:

    回调函数类需继承ACE_Log_Msg_Callback,并实现log方法

class CLogTraceOut  : public  ACE_Log_Msg_Callback
{
public:
    
virtual void log (ACE_Log_Record &log_record) 
    {
        
//输出到VC的输出窗口
        AtlTrace( log_record.msg_data() );
    }
};

    
//在程序的开始出
    CLogTraceOut *pOutput = new CLogTraceOut;
    ACE_LOG_MSG
->set_flags (ACE_Log_Msg::MSG_CALLBACK);   
    ACE_LOG_MSG
->clr_flags (ACE_Log_Msg::STDERR);
    ACE_LOG_MSG
->msg_callback (pOutput );  

        .

    
//程序结束时的清理工作
    ACE_LOG_MSG->clr_flags (ACE_Log_Msg::MSG_CALLBACK);    
    delete pOutput;
原文地址:https://www.cnblogs.com/fangkm/p/1505858.html