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.
129 lines
2.3 KiB
129 lines
2.3 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 <time.h>
|
|
//
|
|
#ifdef WIN32
|
|
#include <io.h>
|
|
#include <direct.h>
|
|
#else
|
|
//#include <unistd.h>
|
|
#endif
|
|
//
|
|
#include "tc_log.h"
|
|
using namespace std;
|
|
|
|
#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* lidy_logFile = NULL;
|
|
char *log_path = NULL;
|
|
|
|
void CreateLogFile(const char* lidy_logFileName)
|
|
{
|
|
int i=0;
|
|
|
|
lidy_logFile = NULL;
|
|
if (log_path) {
|
|
MEM_free(log_path);
|
|
log_path = NULL;
|
|
}
|
|
|
|
log_path = (char*)MEM_alloc((strlen(lidy_logFileName) + 1) * sizeof(char*));
|
|
strcpy(log_path, lidy_logFileName);
|
|
|
|
//get lidy_logFileName
|
|
//sprintf(lidy_logFileName, "%s", lidy_logFileName);
|
|
printf("log file name: %s\n", lidy_logFileName);
|
|
|
|
|
|
//create log file
|
|
if((lidy_logFile = fopen(lidy_logFileName, "a"))==NULL)
|
|
{
|
|
printf("log file create failed\n");
|
|
}
|
|
|
|
}
|
|
|
|
void WriteLog(const char* format, ...)
|
|
{
|
|
va_list arg;
|
|
char tmp[8192];
|
|
|
|
if(lidy_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(lidy_logFile, "%s\n", tmp);
|
|
fflush(lidy_logFile);
|
|
}
|
|
else
|
|
{
|
|
printf("*!Error!*: Log File Not Exist\n");
|
|
}
|
|
}
|
|
|
|
void CloseLog(void)
|
|
{
|
|
if(lidy_logFile)
|
|
{
|
|
fclose(lidy_logFile);
|
|
lidy_logFile = NULL;
|
|
}
|
|
|
|
if (log_path) {
|
|
MEM_free(log_path);
|
|
log_path = NULL;
|
|
}
|
|
}
|
|
|
|
void log_open(void) {
|
|
if (log_path) {
|
|
if ((lidy_logFile = fopen(log_path, "a")) == NULL) {
|
|
printf("log file create failed\n");
|
|
}
|
|
}
|
|
}
|
|
|
|
void log_close(void) {
|
|
if (lidy_logFile) {
|
|
fclose(lidy_logFile);
|
|
lidy_logFile = NULL;
|
|
}
|
|
}
|