You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

104 lines
1.8 KiB

/**
* @file common_itk_util.cpp
* @brief itk warpper utility function
* @author James
* @history
* ===================================================================================
* Date Name Description of Change
* 18-July-2008 Ray
*/
#include <tc/tc.h>
#include <tc/tc_util.h>
#include <tc/tc_arguments.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <time.h>
//
#ifdef WIN32
#include <io.h>
#include <direct.h>
#else
#include <unistd.h>
#endif
//
#include "tc_log.h"
#define ARGS_LENGTH 200
#define MAX_PRINTLINE_LENGTH 2000
#define MAX_PATH_LENGTH 2000
#define MAX_ARGUMENT_LENGTH 400
#define MAX_PARAMNAME_LENGTH 50
#define MAX_FILE_EXT_LENGTH 10
#define TRUE_FLAG 1
#define FALSE_FLAG 0
#define DETAILLOG 1
#define DOFREE(obj) \
{ \
if(obj) \
{ \
MEM_free(obj); \
obj = NULL; \
} \
}
FILE* logFile = NULL;
void CreateLogFile_jk(char* logFileName)
{
int i=0;
logFile = NULL;
//get logFileName
sprintf(logFileName, "%s", logFileName);
printf("log file name: %s\n", logFileName);
//create log file
if((logFile = fopen(logFileName, "w"))==NULL)
{
printf("log file create failed\n");
}
}
void WriteLog_jk(const char* format, ...)
{
va_list arg;
char tmp[MAX_PRINTLINE_LENGTH];
if(logFile)
{
//get the message
memset(tmp, 0, sizeof(tmp));
va_start(arg, format);
vsprintf(tmp, format, arg);
va_end(arg);
//----------print to command window for trace--------//
printf("%s\n", tmp);
//print message to log file
fprintf(logFile, "%s\n", tmp);
fflush(logFile);
}
else
{
printf("*!Error!*: Log File Not Exist\n");
}
}
void CloseLog_jk(void)
{
if(logFile)
{
fclose(logFile);
logFile = NULL;
}
}