예제 #1
0
int TestWLog(int argc, char* argv[])
{
	wLog* log;
	wLogLayout* layout;
	wLogAppender* appender;

	log = WLog_New("CONSOLE_LOG_TEST");

	WLog_SetLogLevel(log, WLOG_INFO);

	WLog_SetLogAppenderType(log, WLOG_APPENDER_CONSOLE);
	appender = WLog_GetLogAppender(log);

	layout = WLog_GetLogLayout(log);
	WLog_Layout_SetPrefixFormat(log, layout, "[%lv:%mn] [%fl|%fn|%ln] - ");

	WLog_ConsoleAppender_SetOutputStream(log, (wLogConsoleAppender*) appender, WLOG_CONSOLE_STDERR);
	WLog_OpenAppender(log);

	WLog_Print(log, WLOG_INFO, "this is a test");
	WLog_Print(log, WLOG_WARN, "this is a %dnd %s", 2, "test");
	WLog_Print(log, WLOG_ERROR, "this is an error");
	WLog_Print(log, WLOG_TRACE, "this is a trace output");

	WLog_CloseAppender(log);
	WLog_Free(log);

	log = WLog_New("FILE_LOG_TEST");

	WLog_SetLogLevel(log, WLOG_WARN);

	WLog_SetLogAppenderType(log, WLOG_APPENDER_FILE);
	appender = WLog_GetLogAppender(log);

	layout = WLog_GetLogLayout(log);
	WLog_Layout_SetPrefixFormat(log, layout, "[%lv:%mn] [%fl|%fn|%ln] - ");

	WLog_FileAppender_SetOutputFileName(log, (wLogFileAppender*) appender, "/tmp/wlog_test.log");
	WLog_OpenAppender(log);

	WLog_Print(log, WLOG_INFO, "this is a test");
	WLog_Print(log, WLOG_WARN, "this is a %dnd %s", 2, "test");
	WLog_Print(log, WLOG_ERROR, "this is an error");
	WLog_Print(log, WLOG_TRACE, "this is a trace output");

	WLog_CloseAppender(log);
	WLog_Free(log);

	return 0;
}
예제 #2
0
파일: wlog.c 프로젝트: teccan/FreeRDP
int WLog_Write(wLog* log, wLogMessage* message)
{
	int status = -1;
	wLogAppender* appender;
	appender = WLog_GetLogAppender(log);

	if (!appender)
		return -1;

	if (!appender->State)
		WLog_OpenAppender(log);

	if (!appender->WriteMessage)
		return -1;

	EnterCriticalSection(&appender->lock);

	if (appender->recursive)
		log_recursion(message->FileName, message->FunctionName, message->LineNumber);
	else
	{
		appender->recursive = TRUE;
		status = appender->WriteMessage(log, appender, message);
		appender->recursive = FALSE;
	}

	LeaveCriticalSection(&appender->lock);
	return status;
}
예제 #3
0
파일: wlog.c 프로젝트: Russkowski/FreeRDP
BOOL WLog_WritePacket(wLog* log, wLogMessage* message)
{
	BOOL status;
	wLogAppender* appender;
	appender = WLog_GetLogAppender(log);

	if (!appender)
		return FALSE;

	if (!appender->active)
		if (!WLog_OpenAppender(log))
			return FALSE;

	if (!appender->WritePacketMessage)
		return FALSE;

	EnterCriticalSection(&appender->lock);

	if (appender->recursive)
		status = log_recursion(message->FileName, message->FunctionName, message->LineNumber);
	else
	{
		appender->recursive = TRUE;
		status = appender->WritePacketMessage(log, appender, message);
		appender->recursive = FALSE;
	}

	LeaveCriticalSection(&appender->lock);
	return status;
}
예제 #4
0
wLogLayout* WLog_GetLogLayout(wLog* log)
{
	wLogAppender* appender;

	appender = WLog_GetLogAppender(log);

	return appender->Layout;
}
예제 #5
0
파일: Appender.c 프로젝트: BUGgs/FreeRDP
wLogAppender* WLog_GetLogAppender(wLog* log)
{
	if (!log)
		return NULL;

	if (!log->Appender)
		return WLog_GetLogAppender(log->Parent);

	return log->Appender;
}
예제 #6
0
int TestWLogCallback(int argc, char* argv[])
{
	wLog* root;
	wLog* logA;
	wLog* logB;
	wLogLayout* layout;
	wLogAppender* appender;
	wLogCallbacks callbacks;

	function = __FUNCTION__;
	WLog_Init();

	root = WLog_GetRoot();

	WLog_SetLogAppenderType(root, WLOG_APPENDER_CALLBACK);

	appender = WLog_GetLogAppender(root);

	callbacks.data = CallbackAppenderData;
	callbacks.image = CallbackAppenderImage;
	callbacks.message = CallbackAppenderMessage;
	callbacks.package = CallbackAppenderPackage;

	if (!WLog_ConfigureAppender(appender, "callbacks", (void *)&callbacks))
		return -1;

	layout = WLog_GetLogLayout(root);
	WLog_Layout_SetPrefixFormat(root, layout, "%mn");

	WLog_OpenAppender(root);

	logA = WLog_Get(channels[0]);
	logB = WLog_Get(channels[1]);

	WLog_SetLogLevel(logA, WLOG_TRACE);
	WLog_SetLogLevel(logB, WLOG_TRACE);

	WLog_Print(logA, messages[0].level, messages[0].msg);
	WLog_Print(logB, messages[1].level, messages[1].msg);
	WLog_Print(logA, messages[2].level, messages[2].msg, 2, "test");
	WLog_Print(logB, messages[3].level, messages[3].msg, 2, "time");
	WLog_Print(logA, messages[4].level, messages[4].msg);
	WLog_Print(logB, messages[5].level, messages[5].msg);
	WLog_Print(logA, messages[6].level, messages[6].msg);
	WLog_Print(logB, messages[7].level, messages[7].msg);

	WLog_CloseAppender(root);

	WLog_Uninit();

	return success ? 0 : -1;
}
예제 #7
0
파일: Appender.c 프로젝트: BUGgs/FreeRDP
int WLog_CloseAppender(wLog* log)
{
	int status = 0;
	wLogAppender* appender;

	appender = WLog_GetLogAppender(log);

	if (!appender)
		return -1;

	if (!appender->Close)
		return 0;

	if (appender->State)
	{
		status = appender->Close(log, appender);
		appender->State = 0;
	}

	return status;
}
예제 #8
0
파일: Appender.c 프로젝트: BUGgs/FreeRDP
int WLog_OpenAppender(wLog* log)
{
	int status = 0;
	wLogAppender* appender;

	appender = WLog_GetLogAppender(log);

	if (!appender)
		return -1;

	if (!appender->Open)
		return 0;

	if (!appender->State)
	{
		status = appender->Open(log, appender);
		appender->State = 1;
	}

	return status;
}
예제 #9
0
BOOL WLog_CloseAppender(wLog* log)
{
	int status = 0;
	wLogAppender* appender;

	appender = WLog_GetLogAppender(log);

	if (!appender)
		return FALSE;

	if (!appender->Close)
		return TRUE;

	if (appender->active)
	{
		status = appender->Close(log, appender);
		appender->active = FALSE;
	}

	return status;
}
예제 #10
0
BOOL WLog_OpenAppender(wLog* log)
{
	int status = 0;
	wLogAppender* appender;

	appender = WLog_GetLogAppender(log);

	if (!appender)
		return FALSE;

	if (!appender->Open)
		return TRUE;

	if (!appender->active)
	{
		status = appender->Open(log, appender);
		appender->active = TRUE;
	}

	return status;
}
예제 #11
0
파일: TestWLog.c 프로젝트: DavBfr/FreeRDP
int TestWLog(int argc, char* argv[])
{
	wLog* root;
	wLog* logA;
	wLog* logB;
	wLogLayout* layout;
	wLogAppender* appender;
	char* tmp_path;
	char* wlog_file;

        if (!(tmp_path = GetKnownPath(KNOWN_PATH_TEMP)))
        {
                fprintf(stderr, "Failed to get temporary directory!\n");
                return -1;
        }

	WLog_Init();

	root = WLog_GetRoot();

	WLog_SetLogAppenderType(root, WLOG_APPENDER_BINARY);

	appender = WLog_GetLogAppender(root);
	if(!WLog_ConfigureAppender(appender, "outputfilename", "test_w.log"))
		return 1;
	if(!WLog_ConfigureAppender(appender, "outputfilepath", tmp_path))
		return 1;

	layout = WLog_GetLogLayout(root);
	WLog_Layout_SetPrefixFormat(root, layout, "[%lv:%mn] [%fl|%fn|%ln] - ");

	WLog_OpenAppender(root);

	logA = WLog_Get("com.test.ChannelA");
	logB = WLog_Get("com.test.ChannelB");

	WLog_SetLogLevel(logA, WLOG_INFO);
	WLog_SetLogLevel(logB, WLOG_ERROR);

	WLog_Print(logA, WLOG_INFO, "this is a test");
	WLog_Print(logA, WLOG_WARN, "this is a %dnd %s", 2, "test");
	WLog_Print(logA, WLOG_ERROR, "this is an error");
	WLog_Print(logA, WLOG_TRACE, "this is a trace output");

	WLog_Print(logB, WLOG_INFO, "just some info");
	WLog_Print(logB, WLOG_WARN, "we're warning a %dnd %s", 2, "time");
	WLog_Print(logB, WLOG_ERROR, "we've got an error");
	WLog_Print(logB, WLOG_TRACE, "leaving a trace behind");

	WLog_CloseAppender(root);

	WLog_Uninit();

	if ((wlog_file = GetCombinedPath(tmp_path, "test_w.log")))
	{
		DeleteFileA(wlog_file);
		free(wlog_file);
	}

	return 0;
}