-
Notifications
You must be signed in to change notification settings - Fork 0
/
logFp.h
40 lines (35 loc) · 1.05 KB
/
logFp.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/** LogFp Ver1.0 diliverUnicorn Copy LEFT Nothing RIGHTS**/
/*
Features:
1.logs events.
2.UTC time with in.
3.Auto end line detect.
4.print by printf.
*/
#include<stdio.h>
#include<time.h>
#include<string.h>
void logFp(int print, const char logstr[])
{
char event[256+22]={0};//22for time string use
FILE * logf_pFile;
logf_pFile = fopen ("Log","a+");
time_t rawtime;
struct tm * timeptr;
if (logf_pFile!=NULL)
{
time ( &rawtime );
timeptr = gmtime ( &rawtime );
//write time in string
sprintf (event,"%d%02d%02d UTC %2d:%02d:%02d ", 1900 + timeptr->tm_year, timeptr->tm_mon, timeptr->tm_mday, timeptr->tm_hour, timeptr->tm_min, timeptr->tm_sec);//utc
//combine time and events
strcat(event,logstr);
//detect endline ,if no endline add on it.
if( NULL==strchr(event,'\n') )
strcat(event,"\n");
fputs (event,logf_pFile);
fclose (logf_pFile);
}
if(print)
printf("%s",event);
}