Exemple #1
0
std::string getProcessName()
{
	std::string name = "MainLog";
	char buf[260] = {0};
#ifdef WIN32
	if (GetModuleFileNameA(NULL, buf, 259) > 0)
	{
		name = buf;
	}
	std::string::size_type pos = name.rfind("\\");
	if (pos != std::string::npos)
	{
		name = name.substr(pos+1, std::string::npos);
	}
	pos = name.rfind(".");
	if (pos != std::string::npos)
	{
		name = name.substr(0, pos-0);
	}

#elif defined(__APPLE__)

	proc_name(getpid(), buf, 260);
	name = buf;
	return name;;
#else
	sprintf(buf, "/proc/%d/cmdline", (int)getpid());
	Log4zFileHandler i;
	i.open(buf, "r");
	if (!i.isOpen())
	{
		return name;
	}
	name = i.readLine();
	i.close();

	std::string::size_type pos = name.rfind("/");
	if (pos != std::string::npos)
	{
		name = name.substr(pos+1, std::string::npos);
	}
#endif


	return name;
}
Exemple #2
0
bool LogerManager::updateConfig()
{
	if (_configFile.empty())
	{
		//LOGW("log4z update config file error. filename is empty.");
		return false;
	}
	Log4zFileHandler f;
	f.open(_configFile.c_str(), "r");
	if (!f.isOpen())
	{
		std::cout << " !!! !!! !!! !!!" << std::endl;
		std::cout << " !!! !!! log4z load config file error. filename=" << _configFile << " !!! !!! " << std::endl;
		std::cout << " !!! !!! !!! !!!" << std::endl;
		return false;
	}
	return configFromStringImpl(f.readContent().c_str(), true);
}
Exemple #3
0
bool LogerManager::updateConfig()
{
    if (_configFile.empty())
    {
        //LOGW("log4z update config file error. filename is empty.");
        return false;
    }
    Log4zFileHandler f;
    f.open(_configFile.c_str(), "rb");
    if (!f.isOpen())
    {
		printf(" !!! !!! !!! !!!\r\n");
		printf(" !!! !!! log4z load config file error. filename=%s  !!! !!! \r\n", _configFile.c_str());
		printf(" !!! !!! !!! !!!\r\n");
        return false;
    }
    return configFromStringImpl(f.readContent().c_str(), true);
}
Exemple #4
0
//! read configure and create with overwriting
bool LogerManager::config(const char* configPath)
{
	if (!_configFile.empty())
	{
		std::cout << " !!! !!! !!! !!!" << std::endl;
		std::cout << " !!! !!! log4z configure error: too many calls to Config. the old config file=" << _configFile << ", the new config file=" << configPath << " !!! !!! " << std::endl;
		std::cout << " !!! !!! !!! !!!" << std::endl;
		return false;
	}
	_configFile = configPath;

	Log4zFileHandler f;
	f.open(_configFile.c_str(), "r");
	if (!f.isOpen())
	{
		std::cout << " !!! !!! !!! !!!" << std::endl;
		std::cout << " !!! !!! log4z load config file error. filename=" << configPath << " !!! !!! " << std::endl;
		std::cout << " !!! !!! !!! !!!" << std::endl;
		return false;
	}
	return configFromStringImpl(f.readContent().c_str(), false);
}
Exemple #5
0
//! read configure and create with overwriting
bool LogerManager::config(const char* configPath)
{
    if (!_configFile.empty())
    {
		printf(" !!! !!! !!! !!!\r\n");
		printf(" !!! !!! log4z configure error: too many calls to Config. the old config file=%s,  the new config file=%s !!! !!! \r\n"
		, _configFile.c_str(), configPath);
		printf(" !!! !!! !!! !!!\r\n");
        return false;
    }
    _configFile = configPath;

    Log4zFileHandler f;
    f.open(_configFile.c_str(), "rb");
    if (!f.isOpen())
    {
		printf(" !!! !!! !!! !!!\r\n");
		printf(" !!! !!! log4z load config file error. filename=%s  !!! !!! \r\n", configPath);
		printf(" !!! !!! !!! !!!\r\n");
        return false;
    }
    return configFromStringImpl(f.readContent().c_str(), false);
}