log日志写法
来源:互联网 发布:windows tasks sched 编辑:程序博客网 时间:2024/04/30 14:37
#define LOG_FILE "./log.txt"#define MAX_LOG_SIZE 20971520 //20M#define G_LOG(fmt, ...) g_mylog(__FILE__, __LINE__, __FUNCTION__, fmt, ##__VA_ARGS__) //LOG日志宏定义//声明gint g_mylog (const gchar* file, gint line, const gchar* function, gchar* fmt, ...);//实现gint g_mylog (const gchar* file, gint line, const gchar* function, gchar* fmt, ...){ va_list arg; char pre[128], tmp[1024]; long clock; struct tm *c_ptr; FILE *fp; struct stat statbuff; time( &clock ); c_ptr = localtime(&clock); sprintf(pre, "[%04d-%02d-%02d %02d:%02d:%02d][%s:%d:%s()]", c_ptr->tm_year+1900, c_ptr->tm_mon+1, c_ptr->tm_mday, c_ptr->tm_hour, c_ptr->tm_min, c_ptr->tm_sec, file, line , function); va_start(arg, fmt); vsprintf(tmp, fmt, arg); va_end (arg); if(!(fp = fopen(LOG_FILE, "at"))) //以追加方式打开文件,不存在则创建 return -1; fprintf(fp, "%s %s\n", pre, tmp); fstat(fileno(fp), &statbuff); if (statbuff.st_size > MAX_LOG_SIZE) //如果文件超过规定大小,则保存为back文件 { char path[1024]; fclose(fp); sprintf(path,"cp %s %s_bak", LOG_FILE, LOG_FILE); system(path); sprintf(path,"rm %s", LOG_FILE); system(path); } else { fclose(fp); } return 0;}
//用法
G_LOG("test1, %d", 8899);
G_LOG("test2");
0 0
- log日志写法
- LOG日志的写法
- 浅谈LOG日志的写法
- 浅谈LOG日志的写法
- Log日志
- Log日志
- log日志
- log 日志
- Log日志
- log日志
- 日志log
- log日志
- Log日志
- log日志
- Log日志
- log日志
- Log 日志
- log日志
- 多线程写不同的file
- 分布式系统概念与设计-CH1:分布式系统的特征
- 深入理解JVM—JVM内存模型
- Android5.X Activity跳转动画
- Android SDK API 15 各安装包下载地址
- log日志写法
- 在eclipse中启动Tomcat,外部浏览器却无法访问8080端口的解决办法
- ViewPager实现图片的自动轮播和无限循环
- OSI模型之物理层概述
- Java序列化和反序列化
- Kurento模块开发指南之三:开发示例 Chroma Filter
- 标准C++中string类型的用法总结
- N款PHP开源系统推荐
- 1 Introduction to Oracle Clusterware Oracle集群软件介绍