Exemple #1
0
    // 初始化日志
    void CLog::InitLog(const char* argv0, const char* dir)
    {
        // 获取不含路径和后缀名的程序名
        const char* slash = strrchr(argv0, '/');
#ifdef _WIN32
        if (!slash)  slash = strrchr(argv0, '\\');
#endif
        slash = slash ? slash + 1 : argv0;
        char buf[1024] = { 0 };
        char* p = strrchr((char*)slash, '.');
        if( p )
            strncpy(buf, slash, (p-slash));
        else
            strcpy(buf, slash);

        // 初始化Google glog
        InitGoogleLogging(buf);

        // 设置日志路径
        SetLogDir(dir);

        // 日志文件只写一个,所以取消Info以外的文件
        SetLogDestination(FATAL,  "");
        SetLogDestination(ERROR,  "");
        SetLogDestination(WARN,   "");

        // 完整的日志文件名称:  <short program name>.<hostname>.log.<date>-<time>.<pid>
        // 拼接日志文件名的前部:<short program name>.<hostname>.log.        
        string hostname;
        GetHostName(&hostname);
        *(buf+strlen(buf)) = '.';
        strcpy(buf+strlen(buf), hostname.c_str());
        strcpy(buf+strlen(buf), ".log.");

        // 设置INFO级别的日志文件前缀
        if( 0 != strcmp(dir, "./"))
        {
            string tmp = dir;
            tmp += buf;
            SetLogDestination(INFO, tmp.c_str());
        }
        else
            SetLogDestination(INFO, buf);
        
        // 默认情况下WARN级别的日志会屏幕输出
        SetStderrThreshold(WARN);

        // 日志是否写屏幕( Debug写,Release不写 )
        //SetAlsoLogToStderr(m_bIsDebug);
        SetLogToStderr(false);
        SetAlsoLogToStderr(false);
    }
Exemple #2
0
bool CExamServerMgr::Start(void)
{
	Stop();
	//以下两行只是创建相应的实例
// 	CMissionFactory::GetInstance();
// 	CListUser::GetInstance();

	SetLogDir();
	
	StartCmdChannel();
	StartFileChannel();
	return true;
}
Exemple #3
0
bool DebugLog::ChangeDirLog(const wxString& newdir)
{
    bool bEnabled = IsEnabled();
    bool bOk = true;

    if (!SetLogDir(newdir))
    {
        wxMessageBox(wxString::Format("invalid folder name %s, debug log folder unchanged", newdir));
        bOk = false;
    }

    Init("debug", bEnabled, true);                // lots of side effects, but all good...
    return bOk;
}
Exemple #4
0
bool GuidingLog::ChangeDirLog(const wxString& newdir)
{
    bool bEnabled = IsEnabled();
    bool bOk = true;

    if (bEnabled)
    {
        Close();
    }
    if (!SetLogDir(newdir))
    {
        wxMessageBox(wxString::Format("invalid folder name %s, log folder unchanged", newdir));
        bOk = false;
    }
    if (bEnabled)                    // if SetLogDir failed, no harm no foul, stay with original. Otherwise
    {
        EnableLogging();             // start fresh...
    }

    return bOk;
}