Esempio n. 1
0
File: log.cpp Progetto: gityf/log
bool log_init(ELogLevel l, const string& moduleName, const string& logDir) {
    string fullPath = logDir + "/" + moduleName + ".access";
    INFO_W.loginit(l, fullPath);
    fullPath = logDir + "/" + moduleName + ".error";
    WARN_W.loginit(l > LL_WARN ? l : LL_WARN, fullPath);
    return true;
}
Esempio n. 2
0
bool logInit(LogLevel l, const char* modulename, const char* logdir, bool verbose) {
	if (access(logdir, 0) == -1) {
		if (mkdir(logdir, S_IRWXU) < 0) {
			fprintf(stderr, "%s create folder failed\n", logdir);
			return false;
		}
	}

	time_t now = time(&now);;
	struct tm vtm;
    localtime_r(&now, &vtm);
	char location_str[LogWriter::M_LOG_PATH_LEN] = {0};
	snprintf(location_str, LogWriter::M_LOG_PATH_LEN, "%s/%s.info.%d%02d%02d-%02d",logdir,modulename,1900+vtm.tm_year,vtm.tm_mon + 1,vtm.tm_mday,vtm.tm_hour);
	INFO_W.loginit(l, location_str, verbose);
	snprintf(location_str, LogWriter::M_LOG_PATH_LEN, "%s/%s.error.%d%02d%02d-%02d", logdir,modulename,1900+vtm.tm_year,vtm.tm_mon + 1,vtm.tm_mday,vtm.tm_hour);
	if(l > LL_WARNING)
		WARN_W.loginit(l, location_str, verbose);
	else
		WARN_W.loginit(LL_WARNING, location_str, verbose);
	return true;
}