Open Broadcaster Software
Free, open source software for live streaming and recording
base.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Hugh Bailey <obs.jim@gmail.com>
3  *
4  * Permission to use, copy, modify, and distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16 
17 #pragma once
18 
19 #include <stdarg.h>
20 
21 #include "c99defs.h"
22 
23 /*
24  * Just contains logging/crash related stuff
25  */
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
31 #define STRINGIFY(x) #x
32 #define STRINGIFY_(x) STRINGIFY(x)
33 #define S__LINE__ STRINGIFY_(__LINE__)
34 
35 #define INT_CUR_LINE __LINE__
36 #define FILE_LINE __FILE__ " (" S__LINE__ "): "
37 
38 enum {
46  LOG_ERROR = 100,
47 
55  LOG_WARNING = 200,
56 
60  LOG_INFO = 300,
61 
65  LOG_DEBUG = 400
66 };
67 
68 typedef void (*log_handler_t)(int lvl, const char *msg, va_list args, void *p);
69 
70 EXPORT void base_get_log_handler(log_handler_t *handler, void **param);
71 EXPORT void base_set_log_handler(log_handler_t handler, void *param);
72 
73 EXPORT void base_set_crash_handler(void (*handler)(const char *, va_list,
74  void *),
75  void *param);
76 
77 EXPORT void blogva(int log_level, const char *format, va_list args);
78 
79 #if !defined(_MSC_VER) && !defined(SWIG)
80 #define PRINTFATTR(f, a) __attribute__((__format__(__printf__, f, a)))
81 #else
82 #define PRINTFATTR(f, a)
83 #endif
84 
85 PRINTFATTR(2, 3)
86 EXPORT void blog(int log_level, const char *format, ...);
87 PRINTFATTR(1, 2)
88 EXPORT void bcrash(const char *format, ...);
89 
90 #undef PRINTFATTR
91 
92 #ifdef __cplusplus
93 }
94 #endif
blog
EXPORT void blog(int log_level, const char *format,...)
LOG_ERROR
@ LOG_ERROR
Definition: base.h:46
EXPORT
#define EXPORT
Definition: c99defs.h:37
log_handler_t
void(* log_handler_t)(int lvl, const char *msg, va_list args, void *p)
Definition: base.h:68
base_set_crash_handler
EXPORT void base_set_crash_handler(void(*handler)(const char *, va_list, void *), void *param)
blogva
EXPORT void blogva(int log_level, const char *format, va_list args)
c99defs.h
bcrash
EXPORT void bcrash(const char *format,...)
LOG_DEBUG
@ LOG_DEBUG
Definition: base.h:65
LOG_INFO
@ LOG_INFO
Definition: base.h:60
base_get_log_handler
EXPORT void base_get_log_handler(log_handler_t *handler, void **param)
PRINTFATTR
#define PRINTFATTR(f, a)
Definition: base.h:80
base_set_log_handler
EXPORT void base_set_log_handler(log_handler_t handler, void *param)
LOG_WARNING
@ LOG_WARNING
Definition: base.h:55