-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlog.cpp
More file actions
85 lines (71 loc) · 1.53 KB
/
log.cpp
File metadata and controls
85 lines (71 loc) · 1.53 KB
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
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <time.h>
#include "log.h"
static int globalErrorType = LM_INFO;
static char gLogFile[1024] = "transcoder.log";
void setErrorType(int type) {
globalErrorType = type;
}
void setLogFile(char *file) {
if (file) {
strcpy(gLogFile, file);
}
}
void LogMessage(int type, char *source, int line, char *fmt, ...) {
va_list parms;
char errortype[25] = "";
int addNewline = 1;
static FILE *filep = 0;
struct tm *tp;
long t;
int parseableOutput = 0;
char timeStamp[255];
memset(timeStamp, '\000', sizeof(timeStamp));
time(&t);
tp = localtime(&t);
strftime(timeStamp, sizeof(timeStamp), "%m/%d/%y %T", tp);
switch (type) {
case LM_ERROR:
strcpy(errortype, "Error");
break;
case LM_INFO:
strcpy(errortype, "Info");
break;
case LM_DEBUG:
strcpy(errortype, "Debug");
break;
default:
strcpy(errortype, "Unknown");
break;
}
if (fmt[strlen(fmt)-1] == '\n') {
addNewline = 0;
}
if (type <= globalErrorType) {
va_start(parms, fmt);
if (filep == 0) {
filep = fopen(gLogFile, "a");
}
if (!filep) {
fprintf(stdout, "Cannot open logfile: %s(%s:%d): ", errortype, source, line);
vfprintf(stdout, fmt, parms);
va_end(parms);
if (addNewline) {
fprintf(stdout, "\n");
}
}
else {
fprintf(filep, "%s %s(%s:%d): ", timeStamp, errortype, source, line);
vfprintf(filep, fmt, parms);
va_end(parms);
if (addNewline) {
fprintf(filep, "\n");
}
fflush(filep);
//fclose(filep);
}
}
}