File size: 4,900 Bytes
9c6594c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*
 * Copyright (c) Facebook, Inc. and its affiliates.
 * All rights reserved.
 *
 * This source code is licensed under the BSD-style license found in the
 * LICENSE file in the root directory of this source tree.
 */

#pragma once

#include <inttypes.h>
#include <stdarg.h>
#include <stdlib.h>

#define CLOG_NONE 0
#define CLOG_FATAL 1
#define CLOG_ERROR 2
#define CLOG_WARNING 3
#define CLOG_INFO 4
#define CLOG_DEBUG 5

#ifndef CLOG_VISIBILITY
#if defined(__ELF__)
#define CLOG_VISIBILITY __attribute__((__visibility__("internal")))
#elif defined(__MACH__)
#define CLOG_VISIBILITY __attribute__((__visibility__("hidden")))
#else
#define CLOG_VISIBILITY
#endif
#endif

#ifndef CLOG_ARGUMENTS_FORMAT
#if defined(__GNUC__)
#define CLOG_ARGUMENTS_FORMAT __attribute__((__format__(__printf__, 1, 2)))
#else
#define CLOG_ARGUMENTS_FORMAT
#endif
#endif

#ifdef __cplusplus
extern "C" {
#endif

CLOG_VISIBILITY void clog_vlog_debug(
    const char* module,
    const char* format,
    va_list args);
CLOG_VISIBILITY void clog_vlog_info(
    const char* module,
    const char* format,
    va_list args);
CLOG_VISIBILITY void clog_vlog_warning(
    const char* module,
    const char* format,
    va_list args);
CLOG_VISIBILITY void clog_vlog_error(
    const char* module,
    const char* format,
    va_list args);
CLOG_VISIBILITY void clog_vlog_fatal(
    const char* module,
    const char* format,
    va_list args);

#define CLOG_DEFINE_LOG_DEBUG(log_debug_function_name, module, level)   \
  CLOG_ARGUMENTS_FORMAT                                                 \
  inline static void log_debug_function_name(const char* format, ...) { \
    if (level >= CLOG_DEBUG) {                                          \
      va_list args;                                                     \
      va_start(args, format);                                           \
      clog_vlog_debug(module, format, args);                            \
      va_end(args);                                                     \
    }                                                                   \
  }

#define CLOG_DEFINE_LOG_INFO(log_info_function_name, module, level)    \
  CLOG_ARGUMENTS_FORMAT                                                \
  inline static void log_info_function_name(const char* format, ...) { \
    if (level >= CLOG_INFO) {                                          \
      va_list args;                                                    \
      va_start(args, format);                                          \
      clog_vlog_info(module, format, args);                            \
      va_end(args);                                                    \
    }                                                                  \
  }

#define CLOG_DEFINE_LOG_WARNING(log_warning_function_name, module, level) \
  CLOG_ARGUMENTS_FORMAT                                                   \
  inline static void log_warning_function_name(const char* format, ...) { \
    if (level >= CLOG_WARNING) {                                          \
      va_list args;                                                       \
      va_start(args, format);                                             \
      clog_vlog_warning(module, format, args);                            \
      va_end(args);                                                       \
    }                                                                     \
  }

#define CLOG_DEFINE_LOG_ERROR(log_error_function_name, module, level)   \
  CLOG_ARGUMENTS_FORMAT                                                 \
  inline static void log_error_function_name(const char* format, ...) { \
    if (level >= CLOG_ERROR) {                                          \
      va_list args;                                                     \
      va_start(args, format);                                           \
      clog_vlog_error(module, format, args);                            \
      va_end(args);                                                     \
    }                                                                   \
  }

#define CLOG_DEFINE_LOG_FATAL(log_fatal_function_name, module, level)   \
  CLOG_ARGUMENTS_FORMAT                                                 \
  inline static void log_fatal_function_name(const char* format, ...) { \
    if (level >= CLOG_FATAL) {                                          \
      va_list args;                                                     \
      va_start(args, format);                                           \
      clog_vlog_fatal(module, format, args);                            \
      va_end(args);                                                     \
    }                                                                   \
    abort();                                                            \
  }

#ifdef __cplusplus
} /* extern "C" */
#endif