C语言日志操作类实例

本文介绍了如何在C语言中实现日志操作,通过示例代码展示了在m.c主函数文件中调用joefunction.h头文件中的日志功能,涉及文件处理、指针和路径操作。
摘要由CSDN通过智能技术生成

包含三个主要的文件:joefunction.h(c), m.c(主函数文件)

1. m.c

#include <stdio.h>
#include <string.h>
#include <time.h>
#include "joefunction.h"

extern FILE *g_logFile;

int main(int argc, char *argv[])
{
	char temp[16] = {0}, fname[20] = {0};
	getTime(temp, TIME_FORMAT_FILENAME);
	sprintf(fname, "%s.log", temp);
	g_logFile = openFile(fname, "a+");
	if(g_logFile)
	{
		int i;
		for(i = 1; i <= 20; i++)
			writeLog("%s()-%dL: CC-[%s%d]", __FILE__, __LINE__, "Hello world", i);
		fclose(g_logFile);
	}

	return 0;
}

2. joefunction.h

// Author:		Joe Black
// Time:		2011-4-5
// Note:		This is a shared file which contains the most useful functions.


#include <stdio.h>

#define MAX_BUFSIZE 250

enum
{
	TIME_FORMAT_DATETIME,
	TIME_FORMAT_TIME,
	TIME_FORMAT_DATE,
	TIME_FORMAT_FIL
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值