ps_usp_log.cpp

来自「可以在Linux上记录日志」· C++ 代码 · 共 89 行

CPP
89
字号
// PS_usp_log.cpp: implementation of the PS_usp_log class.
//
//////////////////////////////////////////////////////////////////////

#include "PS_usp_log.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

//#define LOG_FILE_NAME "/home/kevin/ku6cut/log/ku6cut.log"//"/home/kevin/log/debug.log" //上传操作的日志
//#define DEBUG_FILE_NAME "/home/kevin/ku6cut/log/ku6debug.log"//"/home/kevin/log/debugflie.log" //上传操作的日志

CUspLog::CUspLog(char * logname)
{
	fp_logfile=fopen(logname,"a+");
}

CUspLog::~CUspLog()
{

}
/***************************************************************************
writeLog
****************************************************************************/
/*
void CUspLog::processLog(char * log)
{
	//char l_tmp[1280] = {0};
	//sprintf(l_tmp,"%s",log);
	//fwrite(l_tmp,sizeof(char),strlen(log),fp_logfile);
	fwrite(log,sizeof(char),strlen(log),fp_logfile);
}
*/
//可以传很大的log都没有问题
void CUspLog::writeLog(char * log)
{
	/**
	char l_tmp[128] = {0};
	sprintf(l_tmp,"%s\r\n",log);
	fwrite(l_tmp,sizeof(char),strlen(l_tmp),fp_logfile);
	*/
	fwrite(log,sizeof(char),strlen(log),fp_logfile);
}

void CUspLog::writeLog(int intvalue)
{	
	char l_tmp[100] = {0};
	sprintf(l_tmp,"%d",intvalue);	
	fwrite(l_tmp,sizeof(char),strlen(l_tmp),fp_logfile);
}
void CUspLog::writeLog(char * msginfo, float numinfo)
{
	char l_tmp[128] = {0};
	sprintf(l_tmp,"%s%f\r\n",msginfo,numinfo);
	fwrite(l_tmp,sizeof(char),strlen(l_tmp),fp_logfile);
}
void CUspLog::writeLog(char * msginfo, int numinfo)
{
	char l_tmp[128] = {0};
	sprintf(l_tmp,"%s%d\r\n",msginfo,numinfo);
	fwrite(l_tmp,sizeof(char),strlen(l_tmp),fp_logfile);
}
void CUspLog::writeLog(char * msginfo,char * numinfo)
{
    char l_tmp[128] = {0};
    sprintf(l_tmp,"%s%s\r\n",msginfo,numinfo);
    fwrite(l_tmp,sizeof(char),strlen(l_tmp),fp_logfile);
}
void CUspLog::closeLog(){
	if(fp_logfile!=NULL)
	{
		fclose(fp_logfile);
	}
}

void CUspLog::debugLog(char * debuglogname,char * debuglog){
	FILE * debug_logfile=fopen(debuglogname,"a+");
	fwrite(debuglog,sizeof(char),strlen(debuglog),debug_logfile);
	fclose(debug_logfile);
}

void CUspLog::debugLog(char * debuglogname,int intvalue)
{	
	char l_tmp[50] = {0};
	sprintf(l_tmp,"%d",intvalue);	
	debugLog(debuglogname,l_tmp);
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?