-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathlogging.c
More file actions
49 lines (35 loc) · 786 Bytes
/
logging.c
File metadata and controls
49 lines (35 loc) · 786 Bytes
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
#define _CRT_SECURE_NO_WARNINGS
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <stdarg.h>
#include <sys/types.h>
#include "logging.h"
uint32_t _loggingFlags = (LOG_FLAG_ERROR | LOG_FLAG_WARNING);
static FILE *_logStream = NULL;
void LogMsg(uint32_t Level, const char *Format, ...)
{
va_list vs;
char msg[4096];
if (_loggingFlags & Level) {
if (_logStream == NULL)
_logStream = stderr;
memset(msg, 0, sizeof(msg));
va_start(vs, Format);
vsnprintf(msg, sizeof(msg), Format, vs);
fputs(msg, _logStream);
fflush(_logStream);
va_end(vs);
}
return;
}
int LogSetFile(const char *FileName)
{
int ret = 0;
_logStream = fopen(FileName, "wb");
if (_logStream == NULL)
ret = errno;
return ret;
}