aboutsummaryrefslogtreecommitdiff
path: root/teensy/teensy_log.h
blob: d1dc198672a1cbd8796822a5785ebf3bc78fc4e9 (plain)
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
#ifndef TEENSY_LOG_H_
#define TEENSY_LOG_H_

#include <stdio.h>
#include <stdlib.h>

// Don't include common.h, because this should be included there

#define ty_log_info(...) \
    ty_log_msg(stdout, __FILE__, __LINE__, "info", __VA_ARGS__)
#define ty_log_warn(...) \
    ty_log_msg(stderr, __FILE__, __LINE__, "warn", __VA_ARGS__)
#define ty_log_err(...) \
    ty_log_msg(stderr, __FILE__, __LINE__, "error", __VA_ARGS__)
#define ty_log_fatal(ec, ...) \
    (ty_log_msg(stderr, __FILE__, __LINE__, "fatal", __VA_ARGS__), \
     exit(ec))

#if defined(TEENSY_DEBUG) || !defined(NDEBUG)
#define ty_log_debug(...) \
    ty_log_msg(stderr, __FILE__, __LINE__, "debug", __VA_ARGS__)
#else
#define ty_log_debug(...)
#endif // TEENSY_DEBUG

// To be passed as the exit code to log_fatal()

// General errors
#define TY_ERR_MEM 0x01
#define TY_ERR_IO 0x02
#define TY_ERR_MEM_LEAK 0x03
#define TY_PLATFORM_ERR 0x04

// Rendering errors
#define TY_ERR_GLFW_INIT 0x30
#define TY_ERR_RENDERER_NOT_INIT 0x31
#define TY_ERR_RENDER_OOB 0x32 // Render out-of-bounds

void ty_log_msg(
    FILE *file,
    const char *src_name,
    int src_line,
    const char *type,
    const char *fmt,
    ...
);

void _ty_log_plain(FILE *file, const char *fmt, ...);

#endif // TEENSY_LOG_H_