日期:2014-05-16 浏览次数:21044 次
int Loggers::open(void)//初始化创建新Log文档,用于本次运行时写入。
{
        char logbuf[30] ={0};
        //获取当前时间
        time_t t_time=ACE_OS::time();//当前时间秒数。
        tm*p_tm=ACE_OS::localtime(&t_time);//  定义一个时间结构,当前时间。
        ACE_OS::strftime(logbuf,30,"%Y%m%d%H%M",p_tm);//年月日时分秒输出至logbuf。
        std::string filena;
        filena.assign(logbuf,strlen(logbuf));
        filena += ".log";//形成文件名。
        char buf[1024]={0};
        sprintf(buf,"touch %s",filena.c_str());
        ACE_OS::system(buf);
        logfile.open(filena.c_str(),ios::in|ios::out|ios::app);//创建新log文档,以时间命名。
        if (!logfile)
        {
                std::cout << "err: unable to open the log file: "<< std::endl;
                return -1;
        }
        std::cout << "Log initialize success!" << std::endl;
        std::cout << "Logfile created in " << filena << std::endl;
        return 0;
}
        logfile.open(filena.c_str(),ios::in|ios::out|ios::app);//创建新log文档,以时间命名。
------解决方案--------------------
采用默认的最好。oftream,iftream对应有默认的打开方式。