-
Notifications
You must be signed in to change notification settings - Fork 13
/
Awful_logger.cpp
69 lines (56 loc) · 2.29 KB
/
Awful_logger.cpp
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
/*==================================================================================================
Module Name: Awful_logger.cpp
General Description: Logging utility functionality is defined here.
====================================================================================================
Revision History:
Modification
Author Date Major Changes
---------------------- ------------ -------------
Anonymous 09/01/2008 Initial version
==================================================================================================*/
//=================================================================================================
// Include Section
//=================================================================================================
#include <iostream>
#include <stdio.h>
//=================================================================================================
// Global/Static Variable Section
//=================================================================================================
#define LOGGER_FILE_NAME "awful_logs.txt"
//=================================================================================================
// Global function declaration
//=================================================================================================
void AwfulLogData(const char* filename, unsigned int line, const char* text)
{
FILE *fhandle = NULL;
char *buf = NULL;
unsigned int len = 0;
fhandle = fopen(LOGGER_FILE_NAME, "a+");
if (NULL != fhandle)
{
len = strlen(text);
if (filename != NULL)
{
len += strlen(filename);
}
if (line != -1)
{
len += 16; // dunno why...
}
buf = (char *) malloc(len * sizeof(char));
if (buf != NULL)
{
if (filename != NULL)
{
sprintf(buf, "%s - %u: %s\n", filename, line, text);
}
else
{
sprintf(buf, "%s\n", text);
}
fwrite(buf, strlen(buf), 1, fhandle);
free(buf);
}
fclose(fhandle);
}
}