|
|
|
|
@ -1,7 +1,7 @@
|
|
|
|
|
/*
|
|
|
|
|
* This file is part of the EasyLogger Library.
|
|
|
|
|
*
|
|
|
|
|
* Copyright (c) 2015, Armink, <armink.ztl@gmail.com>
|
|
|
|
|
* Copyright (c) 2015-2017, Armink, <armink.ztl@gmail.com>
|
|
|
|
|
*
|
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
|
* a copy of this software and associated documentation files (the
|
|
|
|
|
@ -50,24 +50,75 @@ extern "C" {
|
|
|
|
|
#define ELOG_LVL_TOTAL_NUM 6
|
|
|
|
|
|
|
|
|
|
/* EasyLogger software version number */
|
|
|
|
|
#define ELOG_SW_VERSION "1.12.19"
|
|
|
|
|
#define ELOG_SW_VERSION "2.0.0"
|
|
|
|
|
|
|
|
|
|
/* EasyLogger assert for developer. */
|
|
|
|
|
#ifdef ELOG_ASSERT_ENABLE
|
|
|
|
|
#define ELOG_ASSERT(EXPR) \
|
|
|
|
|
if (!(EXPR)) \
|
|
|
|
|
{ \
|
|
|
|
|
#define ELOG_ASSERT(EXPR) \
|
|
|
|
|
if (!(EXPR)) \
|
|
|
|
|
{ \
|
|
|
|
|
if (elog_assert_hook == NULL) { \
|
|
|
|
|
elog_a("elog", "(%s) has assert failed at %s:%ld.", #EXPR, __FUNCTION__, __LINE__); \
|
|
|
|
|
while (1); \
|
|
|
|
|
} else { \
|
|
|
|
|
elog_assert_hook(#EXPR, __FUNCTION__, __LINE__); \
|
|
|
|
|
} \
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
#define ELOG_ASSERT(EXPR) ((void)0);
|
|
|
|
|
#define ELOG_ASSERT(EXPR) ((void)0);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifndef ELOG_OUTPUT_ENABLE
|
|
|
|
|
#define elog_a(tag, ...)
|
|
|
|
|
#define elog_e(tag, ...)
|
|
|
|
|
#define elog_w(tag, ...)
|
|
|
|
|
#define elog_i(tag, ...)
|
|
|
|
|
#define elog_d(tag, ...)
|
|
|
|
|
#define elog_v(tag, ...)
|
|
|
|
|
#else /* ELOG_OUTPUT_ENABLE */
|
|
|
|
|
#if ELOG_OUTPUT_LVL >= ELOG_LVL_ASSERT
|
|
|
|
|
#define elog_assert(tag, ...) \
|
|
|
|
|
elog_output(ELOG_LVL_ASSERT, tag, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__)
|
|
|
|
|
#else
|
|
|
|
|
#define elog_assert(tag, ...)
|
|
|
|
|
#endif /* ELOG_OUTPUT_LVL >= ELOG_LVL_ASSERT */
|
|
|
|
|
|
|
|
|
|
#if ELOG_OUTPUT_LVL >= ELOG_LVL_ERROR
|
|
|
|
|
#define elog_error(tag, ...) \
|
|
|
|
|
elog_output(ELOG_LVL_ERROR, tag, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__)
|
|
|
|
|
#else
|
|
|
|
|
#define elog_error(tag, ...)
|
|
|
|
|
#endif /* ELOG_OUTPUT_LVL >= ELOG_LVL_ERROR */
|
|
|
|
|
|
|
|
|
|
#if ELOG_OUTPUT_LVL >= ELOG_LVL_WARN
|
|
|
|
|
#define elog_warn(tag, ...) \
|
|
|
|
|
elog_output(ELOG_LVL_WARN, tag, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__)
|
|
|
|
|
#else
|
|
|
|
|
#define elog_warn(tag, ...)
|
|
|
|
|
#endif /* ELOG_OUTPUT_LVL >= ELOG_LVL_WARN */
|
|
|
|
|
|
|
|
|
|
#if ELOG_OUTPUT_LVL >= ELOG_LVL_INFO
|
|
|
|
|
#define elog_info(tag, ...) \
|
|
|
|
|
elog_output(ELOG_LVL_INFO, tag, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__)
|
|
|
|
|
#else
|
|
|
|
|
#define elog_info(tag, ...)
|
|
|
|
|
#endif /* ELOG_OUTPUT_LVL >= ELOG_LVL_INFO */
|
|
|
|
|
|
|
|
|
|
#if ELOG_OUTPUT_LVL >= ELOG_LVL_DEBUG
|
|
|
|
|
#define elog_debug(tag, ...) \
|
|
|
|
|
elog_output(ELOG_LVL_DEBUG, tag, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__)
|
|
|
|
|
#else
|
|
|
|
|
#define elog_debug(tag, ...)
|
|
|
|
|
#endif /* ELOG_OUTPUT_LVL >= ELOG_LVL_DEBUG */
|
|
|
|
|
|
|
|
|
|
#if ELOG_OUTPUT_LVL == ELOG_LVL_VERBOSE
|
|
|
|
|
#define elog_verbose(tag, ...) \
|
|
|
|
|
elog_output(ELOG_LVL_VERBOSE, tag, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__)
|
|
|
|
|
#else
|
|
|
|
|
#define elog_verbose(tag, ...)
|
|
|
|
|
#endif /* ELOG_OUTPUT_LVL == ELOG_LVL_VERBOSE */
|
|
|
|
|
#endif /* ELOG_OUTPUT_ENABLE */
|
|
|
|
|
|
|
|
|
|
/* all formats index */
|
|
|
|
|
typedef enum {
|
|
|
|
|
ELOG_FMT_LVL = 1 << 0, /**< level */
|
|
|
|
|
@ -132,67 +183,58 @@ void elog_assert_set_hook(void (*hook)(const char* expr, const char* func, size_
|
|
|
|
|
int8_t elog_find_lvl(const char *log);
|
|
|
|
|
const char *elog_find_tag(const char *log, uint8_t lvl, size_t *tag_len);
|
|
|
|
|
|
|
|
|
|
#ifndef ELOG_OUTPUT_ENABLE
|
|
|
|
|
|
|
|
|
|
#define elog_a(tag, ...)
|
|
|
|
|
#define elog_e(tag, ...)
|
|
|
|
|
#define elog_w(tag, ...)
|
|
|
|
|
#define elog_i(tag, ...)
|
|
|
|
|
#define elog_d(tag, ...)
|
|
|
|
|
#define elog_v(tag, ...)
|
|
|
|
|
|
|
|
|
|
#else /* ELOG_OUTPUT_ENABLE */
|
|
|
|
|
#define elog_a(tag, ...) elog_assert(tag, __VA_ARGS__)
|
|
|
|
|
#define elog_e(tag, ...) elog_error(tag, __VA_ARGS__)
|
|
|
|
|
#define elog_w(tag, ...) elog_warn(tag, __VA_ARGS__)
|
|
|
|
|
#define elog_i(tag, ...) elog_info(tag, __VA_ARGS__)
|
|
|
|
|
#define elog_d(tag, ...) elog_debug(tag, __VA_ARGS__)
|
|
|
|
|
#define elog_v(tag, ...) elog_verbose(tag, __VA_ARGS__)
|
|
|
|
|
|
|
|
|
|
#if ELOG_OUTPUT_LVL >= ELOG_LVL_ASSERT
|
|
|
|
|
#define elog_assert(tag, ...) \
|
|
|
|
|
elog_output(ELOG_LVL_ASSERT, tag, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__)
|
|
|
|
|
/**
|
|
|
|
|
* log API short definition
|
|
|
|
|
* NOTE: The `LOG_TAG` and `LOG_LVL` must defined before including the <elog.h> when you want to use log_x API.
|
|
|
|
|
*/
|
|
|
|
|
#if !defined(LOG_TAG)
|
|
|
|
|
#define LOG_TAG "NO_TAG"
|
|
|
|
|
#endif
|
|
|
|
|
#if !defined(LOG_LVL)
|
|
|
|
|
#define LOG_LVL ELOG_LVL_VERBOSE
|
|
|
|
|
#endif
|
|
|
|
|
#if LOG_LVL >= ELOG_LVL_ASSERT
|
|
|
|
|
#define log_a(...) elog_a(LOG_TAG, __VA_ARGS__)
|
|
|
|
|
#else
|
|
|
|
|
#define elog_assert(tag, ...)
|
|
|
|
|
#define log_a(...) ((void)0);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#if ELOG_OUTPUT_LVL >= ELOG_LVL_ERROR
|
|
|
|
|
#define elog_error(tag, ...) \
|
|
|
|
|
elog_output(ELOG_LVL_ERROR, tag, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__)
|
|
|
|
|
#if LOG_LVL >= ELOG_LVL_ERROR
|
|
|
|
|
#define log_e(...) elog_e(LOG_TAG, __VA_ARGS__)
|
|
|
|
|
#else
|
|
|
|
|
#define elog_error(tag, ...)
|
|
|
|
|
#define log_e(...) ((void)0);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#if ELOG_OUTPUT_LVL >= ELOG_LVL_WARN
|
|
|
|
|
#define elog_warn(tag, ...) \
|
|
|
|
|
elog_output(ELOG_LVL_WARN, tag, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__)
|
|
|
|
|
#if LOG_LVL >= ELOG_LVL_WARN
|
|
|
|
|
#define log_w(...) elog_w(LOG_TAG, __VA_ARGS__)
|
|
|
|
|
#else
|
|
|
|
|
#define elog_warn(tag, ...)
|
|
|
|
|
#define log_w(...) ((void)0);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#if ELOG_OUTPUT_LVL >= ELOG_LVL_INFO
|
|
|
|
|
#define elog_info(tag, ...) \
|
|
|
|
|
elog_output(ELOG_LVL_INFO, tag, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__)
|
|
|
|
|
#if LOG_LVL >= ELOG_LVL_INFO
|
|
|
|
|
#define log_i(...) elog_i(LOG_TAG, __VA_ARGS__)
|
|
|
|
|
#else
|
|
|
|
|
#define elog_info(tag, ...)
|
|
|
|
|
#define log_i(...) ((void)0);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#if ELOG_OUTPUT_LVL >= ELOG_LVL_DEBUG
|
|
|
|
|
#define elog_debug(tag, ...) \
|
|
|
|
|
elog_output(ELOG_LVL_DEBUG, tag, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__)
|
|
|
|
|
#if LOG_LVL >= ELOG_LVL_DEBUG
|
|
|
|
|
#define log_d(...) elog_d(LOG_TAG, __VA_ARGS__)
|
|
|
|
|
#else
|
|
|
|
|
#define elog_debug(tag, ...)
|
|
|
|
|
#define log_d(...) ((void)0);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#if ELOG_OUTPUT_LVL == ELOG_LVL_VERBOSE
|
|
|
|
|
#define elog_verbose(tag, ...) \
|
|
|
|
|
elog_output(ELOG_LVL_VERBOSE, tag, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__)
|
|
|
|
|
#if LOG_LVL >= ELOG_LVL_VERBOSE
|
|
|
|
|
#define log_v(...) elog_v(LOG_TAG, __VA_ARGS__)
|
|
|
|
|
#else
|
|
|
|
|
#define elog_verbose(tag, ...)
|
|
|
|
|
#define log_v(...) ((void)0);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#endif /* ELOG_OUTPUT_ENABLE */
|
|
|
|
|
|
|
|
|
|
#define elog_a(tag, ...) elog_assert(tag, __VA_ARGS__)
|
|
|
|
|
#define elog_e(tag, ...) elog_error(tag, __VA_ARGS__)
|
|
|
|
|
#define elog_w(tag, ...) elog_warn(tag, __VA_ARGS__)
|
|
|
|
|
#define elog_i(tag, ...) elog_info(tag, __VA_ARGS__)
|
|
|
|
|
#define elog_d(tag, ...) elog_debug(tag, __VA_ARGS__)
|
|
|
|
|
#define elog_v(tag, ...) elog_verbose(tag, __VA_ARGS__)
|
|
|
|
|
/* assert API short definition */
|
|
|
|
|
#if !defined(assert)
|
|
|
|
|
#define assert ELOG_ASSERT
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/* elog_buf.c */
|
|
|
|
|
void elog_buf_enabled(bool enabled);
|
|
|
|
|
|