-
Notifications
You must be signed in to change notification settings - Fork 2
/
dbglog.c
executable file
·92 lines (71 loc) · 2.16 KB
/
dbglog.c
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <errno.h>
#include "dbglog.h"
static char sMyKey[32];
static char sDebugLog[255];
static int sDebug;
static int sVerbose = 0;
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
void
InitDBGLog( char *_Key, char * _FileName, int _Debug, int _Verbose )
{
strcpy( sMyKey, _Key );
strcpy( sDebugLog, _FileName );
sVerbose = _Verbose;
sDebug = _Debug;
}
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
void
WriteDBGLog( char *_Str )
{
FILE *FH;
time_t tt;
struct tm *tm;
char header[512];
tt = time(NULL);
tm = localtime(&tt);
sprintf(header, "%s-%04d/%02d/%02d %02d:%02d:%02d ", sMyKey, tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
if (sDebug)
{
FH = fopen(sDebugLog, "a+");
if (FH == NULL)
{
return;
} /* endif */
fputs( header, FH );
fputs( _Str, FH );
if ( _Str[ strlen( _Str) - 1] != '\n' )
fprintf( FH, "\n" );
fclose(FH);
} /* endif */
if ( sVerbose )
printf( "%s %s\n", header, _Str );
}
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
void
WriteRunLog( char *_Str )
{
FILE *FH;
time_t tt;
struct tm *tm;
FH = fopen("./runlog", "a+");
if (FH == NULL)
{
return;
} /* endif */
tt = time(NULL);
tm = localtime(&tt);
fprintf(FH, "%04d/%02d/%02d,%02d:%02d:%02d, ", tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
fputs( _Str, FH );
if ( _Str[ strlen( _Str) - 1] != '\n' )
fprintf( FH, "\n" );
fclose(FH);
}