⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 log.c

📁 公司业务而自己写的网关通讯程序,网关是平台的.不过对OCI有兴趣的不妨看看. Oracle Oci select exec update 多线程 IVR 网关通讯 linux 日志文件操作
💻 C
字号:
#include <stdio.h>#include "log.h"#include <time.h>#include <pthread.h>
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
char lastdate[20];FILE *pLogFile=NULL;void log(char* loglevel,char* logmsg,int toscreen){    struct tm *tm_ptr, timestruct;    time_t the_time;    char tmpbuf[1024];    char *result;    (void) time(&the_time);    tm_ptr = localtime(&the_time);    strftime(tmpbuf, 50, "%Y-%m-%d", tm_ptr);        strcat(tmpbuf,".");    strcat(tmpbuf,loglevel);
	pthread_mutex_lock(&mutex);	    if(!pLogFile || strcmp(lastdate,tmpbuf)!=0){			if(pLogFile){				fclose(pLogFile);			}			strcpy(lastdate,tmpbuf);			pLogFile = fopen(tmpbuf,"a");		}	    if(!pLogFile){	    	printf("can not open logfile:%s\n",tmpbuf);			pthread_mutex_unlock(&mutex);    		    	return;	    }		strftime( tmpbuf, 1024,			"[%Y-%m-%d %H:%M:%S] ", tm_ptr );		strcat(tmpbuf,logmsg);		strcat(tmpbuf,"\n");		if(toscreen)printf(tmpbuf);		fwrite(tmpbuf,sizeof(char),strlen(tmpbuf),pLogFile);		pthread_mutex_unlock(&mutex);	    return;}void closelog(){	if(!pLogFile){		fclose(pLogFile);	}	}

⌨️ 快捷键说明

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