aboutsummaryrefslogtreecommitdiff
path: root/log/include/log/log.h
blob: bd0c20c56ecced974b1a86c16b3346c7c3d2782e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#pragma once

#include <stdio.h>

// Undef any previously defined log macros (from cassert.h, for example) to
// redefine them without compiler warnings.
#undef LOG
#undef LOGD
#undef LOGI
#undef LOGW
#undef LOGE

#define LOG(channel, tag, format, ...)                      \
  {                                                         \
    fprintf(                                                \
        channel, "[%s] %s:%d " format "\n", #tag, __FILE__, \
        __LINE__ __VA_OPT__(, ) __VA_ARGS__);               \
  }

#define LOGD(format, ...) LOG(stdout, DEBUG, format, __VA_ARGS__)
#define LOGI(format, ...) LOG(stdout, INFO, format, __VA_ARGS__)
#define LOGW(format, ...) LOG(stdout, WARN, format, __VA_ARGS__)
#define LOGE(format, ...) LOG(stderr, ERROR, format, __VA_ARGS__)