]>
git.bts.cx Git - benzene.git/blob - src_platform/sdl/bz/debug/log.c
1 #include <bz/debug/log_internal.h>
3 #include <stb_sprintf.h>
11 #define _OUTPUT_PRELUDE(dst, name, filename, lineNumber) { \
14 struct tm *timeinfo = localtime(&t); \
15 output(dst, name",%02d:%02d:%02d,\"%s\"@%d,", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, filename, lineNumber); \
18 static char buffer
[STB_SPRINTF_MIN
];
20 static int errorFD
= STDERR_FILENO
;
21 static int outputFD
= STDOUT_FILENO
;
23 static char *sprintfCallback(char const *buf
, void *user
, int len
) {
24 int fd
= (int)((long)user
);
25 write(fd
, buf
, (size_t)len
);
29 static void output(int fd
, const char *fmt
, ...) {
32 stbsp_vsprintfcb(sprintfCallback
, (void *)((long)fd
), buffer
, fmt
, args
);
36 void _bzLog(const char *filename
, unsigned long lineNumber
, const char *fmt
, ...) {
39 _OUTPUT_PRELUDE(outputFD
, "LOG", filename
, lineNumber
);
40 stbsp_vsprintfcb(sprintfCallback
, (void *)((long)outputFD
), buffer
, fmt
, args
);
41 output(outputFD
, "\n");
45 void _bzError(const char *filename
, unsigned long lineNumber
, const char *fmt
, ...) {
48 _OUTPUT_PRELUDE(errorFD
, "ERROR", filename
, lineNumber
);
49 stbsp_vsprintfcb(sprintfCallback
, (void *)((long)errorFD
), buffer
, fmt
, args
);
50 output(errorFD
, "\n");
54 void bzLogInit(const char *outputFilePath
) {
55 if (outputFilePath
!= NULL
) {
56 outputFD
= errorFD
= open(outputFilePath
, O_CREAT
| O_WRONLY
, S_IRUSR
| S_IWUSR
| S_IRGRP
| S_IWGRP
| S_IROTH
| S_IWOTH
);
60 void bzLogTeardown() {