2020-03-16 08:43:57 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
|
|
|
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* @file bh_log.h
|
|
|
|
* @date Tue Nov 8 18:19:10 2011
|
|
|
|
*
|
|
|
|
* @brief This log system supports wrapping multiple outputs into one
|
|
|
|
* log message. This is useful for outputting variable-length logs
|
|
|
|
* without additional memory overhead (the buffer for concatenating
|
|
|
|
* the message), e.g. exception stack trace, which cannot be printed
|
|
|
|
* by a single log calling without the help of an additional buffer.
|
|
|
|
* Avoiding additional memory buffer is useful for resource-constraint
|
|
|
|
* systems. It can minimize the impact of log system on applications
|
|
|
|
* and logs can be printed even when no enough memory is available.
|
|
|
|
* Functions with prefix "_" are private functions. Only macros that
|
|
|
|
* are not start with "_" are exposed and can be used.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _BH_LOG_H
|
|
|
|
#define _BH_LOG_H
|
|
|
|
|
|
|
|
#include "bh_platform.h"
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
typedef enum {
|
2020-05-12 05:06:37 +00:00
|
|
|
BH_LOG_LEVEL_FATAL = 0,
|
|
|
|
BH_LOG_LEVEL_ERROR = 1,
|
|
|
|
BH_LOG_LEVEL_WARNING = 2,
|
|
|
|
BH_LOG_LEVEL_DEBUG = 3,
|
|
|
|
BH_LOG_LEVEL_VERBOSE = 4
|
2020-03-16 08:43:57 +00:00
|
|
|
} LogLevel;
|
|
|
|
|
|
|
|
void
|
|
|
|
bh_log_set_verbose_level(uint32 level);
|
|
|
|
|
|
|
|
void
|
|
|
|
bh_log(LogLevel log_level, const char *file, int line, const char *fmt, ...);
|
|
|
|
|
2020-09-16 09:53:03 +00:00
|
|
|
#ifdef BH_PLATFORM_NUTTX
|
|
|
|
|
|
|
|
#undef LOG_FATAL
|
|
|
|
#undef LOG_ERROR
|
|
|
|
#undef LOG_WARNING
|
|
|
|
#undef LOG_VERBOSE
|
|
|
|
#undef LOG_DEBUG
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2021-01-28 08:16:02 +00:00
|
|
|
#if BH_DEBUG != 0
|
2021-10-14 01:12:07 +00:00
|
|
|
#define LOG_FATAL(...) \
|
|
|
|
bh_log(BH_LOG_LEVEL_FATAL, __FILE__, __LINE__, __VA_ARGS__)
|
2020-06-02 06:53:06 +00:00
|
|
|
#else
|
2021-10-14 01:12:07 +00:00
|
|
|
#define LOG_FATAL(...) \
|
|
|
|
bh_log(BH_LOG_LEVEL_FATAL, __FUNCTION__, __LINE__, __VA_ARGS__)
|
2020-06-02 06:53:06 +00:00
|
|
|
#endif
|
|
|
|
|
2021-10-14 01:12:07 +00:00
|
|
|
#define LOG_ERROR(...) bh_log(BH_LOG_LEVEL_ERROR, NULL, 0, __VA_ARGS__)
|
2020-05-12 05:06:37 +00:00
|
|
|
#define LOG_WARNING(...) bh_log(BH_LOG_LEVEL_WARNING, NULL, 0, __VA_ARGS__)
|
|
|
|
#define LOG_VERBOSE(...) bh_log(BH_LOG_LEVEL_VERBOSE, NULL, 0, __VA_ARGS__)
|
2020-03-16 08:43:57 +00:00
|
|
|
|
2021-01-28 08:16:02 +00:00
|
|
|
#if BH_DEBUG != 0
|
2021-10-14 01:12:07 +00:00
|
|
|
#define LOG_DEBUG(...) \
|
|
|
|
bh_log(BH_LOG_LEVEL_DEBUG, __FILE__, __LINE__, __VA_ARGS__)
|
2020-06-02 06:53:06 +00:00
|
|
|
#else
|
2021-10-14 01:12:07 +00:00
|
|
|
#define LOG_DEBUG(...) (void)0
|
2020-06-02 06:53:06 +00:00
|
|
|
#endif
|
|
|
|
|
2020-03-20 08:06:40 +00:00
|
|
|
void
|
|
|
|
bh_print_time(const char *prompt);
|
|
|
|
|
2020-03-16 08:43:57 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2021-10-14 01:12:07 +00:00
|
|
|
#endif /* _BH_LOG_H */
|