如何更改日志格式 [英] How to change the format of log

查看:116
本文介绍了如何更改日志格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个程序可以使用套接字连接到医院的机器,向机器发送请求,从机器接收数据并解析从机器接收的数据.
它将所有数据字段写入txt文件中,例如

I have a program to connect to an hospital machine using socket,send request to the machine,receive data from the machine and parse the data received from the machine.
It write all the data fields in the txt file like

 09/17/12::17:28:17 status of machine is-on
09/17/12::17:28:17  Mode of machine is-active
09/17/12::17:28:17 Temp is -38



但是现在随着需求的变化,我希望将数据写为:-



But Now as the requirement changes i want the data to be written as:-

09/17/12::17:28:17 on,active,38 



我该怎么办?
请通过伪指令告诉我,您的身边将对您有很大帮助.



How can i do that?
Please tell by pseudo i would be great help from your side.

推荐答案

解析器将在X时刻获得三个信息(打开,活动,温度),然后解析器将其写入要这样归档.

Parser will get three information(On, Active, Temperature) at time X, then parser write it to file like this.

printf( "%s status of machine is %s", X, On );
printf( "%s Mode of machine is- %s", X, Active );
printf( "%s Temp is- %s", X, Temperature);



请这样更改



Please change like this

printf( "%s %s,%s,%s", X, On, Active, Temperature );


time_t rawtime;
struct tm * timeinfo;

time ( &rawtime );
timeinfo = localtime ( &rawtime );


char datebuff[1024];

sprintf( datebuff, "%02d/%02d/%02d::%02d:%02d:%02d", timeinfo->tm_mon + 1, timeinfo->tm_mday, 
( timeinfo->tm_year + 1900 ) % 100, timeinfo->tm_hour,
timeinfo->tm_min, timeinfo->tm_sec );

sprintf(buf,"%s,%s,%s,%d", datebuff, status_of_mac, hine,mode,tmp);
WriteToDataFile(buf);


这篇关于如何更改日志格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆