yolobs-studio/libobs/util/base.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

95 lines
2.5 KiB
C
Raw Normal View History

2016-02-23 23:16:51 +00:00
/*
* Copyright (c) 2013 Hugh Bailey <obs.jim@gmail.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#pragma once
#include <stdarg.h>
#include "c99defs.h"
/*
* Just contains logging/crash related stuff
*/
#ifdef __cplusplus
extern "C" {
#endif
#define STRINGIFY(x) #x
#define STRINGIFY_(x) STRINGIFY(x)
#define S__LINE__ STRINGIFY_(__LINE__)
#define INT_CUR_LINE __LINE__
#define FILE_LINE __FILE__ " (" S__LINE__ "): "
enum {
/**
* Use if there's a problem that can potentially affect the program,
* but isn't enough to require termination of the program.
*
* Use in creation functions and core subsystem functions. Places that
* should definitely not fail.
*/
2019-09-22 21:19:10 +00:00
LOG_ERROR = 100,
2016-02-23 23:16:51 +00:00
/**
* Use if a problem occurs that doesn't affect the program and is
* recoverable.
*
2017-06-29 19:01:10 +00:00
* Use in places where failure isn't entirely unexpected, and can
2016-02-23 23:16:51 +00:00
* be handled safely.
*/
LOG_WARNING = 200,
/**
2017-06-29 19:01:10 +00:00
* Informative message to be displayed in the log.
2016-02-23 23:16:51 +00:00
*/
2019-09-22 21:19:10 +00:00
LOG_INFO = 300,
2016-02-23 23:16:51 +00:00
/**
* Debug message to be used mostly by developers.
*/
2019-09-22 21:19:10 +00:00
LOG_DEBUG = 400
2016-02-23 23:16:51 +00:00
};
typedef void (*log_handler_t)(int lvl, const char *msg, va_list args, void *p);
EXPORT void base_get_log_handler(log_handler_t *handler, void **param);
EXPORT void base_set_log_handler(log_handler_t handler, void *param);
2019-09-22 21:19:10 +00:00
EXPORT void base_set_crash_handler(void (*handler)(const char *, va_list,
void *),
void *param);
2016-02-23 23:16:51 +00:00
EXPORT void blogva(int log_level, const char *format, va_list args);
2018-02-19 19:54:37 +00:00
#if !defined(_MSC_VER) && !defined(SWIG)
2016-02-23 23:16:51 +00:00
#define PRINTFATTR(f, a) __attribute__((__format__(__printf__, f, a)))
#else
#define PRINTFATTR(f, a)
#endif
PRINTFATTR(2, 3)
EXPORT void blog(int log_level, const char *format, ...);
PRINTFATTR(1, 2)
EXPORT void bcrash(const char *format, ...);
#undef PRINTFATTR
#ifdef __cplusplus
}
#endif