1
0
mirror of https://github.com/armink/EasyLogger.git synced 2025-01-20 08:12:53 +08:00

1、【增加】C99的stdbool.h,保证项目全部采用C99的bool的类型。

Signed-off-by: armink <armink.ztl@gmail.com>
This commit is contained in:
armink 2015-05-16 14:02:53 +08:00
parent ccd4fd8520
commit 3eef3c5ab5
3 changed files with 22 additions and 18 deletions

View File

@ -27,9 +27,9 @@ MSH_CMD_EXPORT(get_cpuusage, Get control board cpu usage);
static void elog(uint8_t argc, char **argv) { static void elog(uint8_t argc, char **argv) {
if (argc > 1) { if (argc > 1) {
if (!strcmp(argv[1], "on") || !strcmp(argv[1], "ON")) { if (!strcmp(argv[1], "on") || !strcmp(argv[1], "ON")) {
elog_set_output_enabled(TRUE); elog_set_output_enabled(true);
} else if (!strcmp(argv[1], "off") || !strcmp(argv[1], "OFF")) { } else if (!strcmp(argv[1], "off") || !strcmp(argv[1], "OFF")) {
elog_set_output_enabled(FALSE); elog_set_output_enabled(false);
} else { } else {
rt_kprintf("Please input elog on or elog off.\n"); rt_kprintf("Please input elog on or elog off.\n");
} }

View File

@ -23,7 +23,13 @@
#ifndef __ELOG_H__ #ifndef __ELOG_H__
#define __ELOG_H__ #define __ELOG_H__
#include "types.h" #include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
#ifndef NULL
#define NULL 0
#endif
/* output log's level */ /* output log's level */
#define ELOG_LVL_ASSERT 0 #define ELOG_LVL_ASSERT 0
@ -47,7 +53,7 @@
/* output filter's keyword max length */ /* output filter's keyword max length */
#define ELOG_FILTER_KW_MAX_LEN 16 #define ELOG_FILTER_KW_MAX_LEN 16
/* EasyLogger software version number */ /* EasyLogger software version number */
#define ELOG_SW_VERSION "0.05.15" #define ELOG_SW_VERSION "0.05.16"
/* EasyLogger assert for developer. */ /* EasyLogger assert for developer. */
#define ELOG_ASSERT(EXPR) \ #define ELOG_ASSERT(EXPR) \
@ -76,8 +82,8 @@ typedef enum {
/* elog.c */ /* elog.c */
ElogErrCode elog_init(void); ElogErrCode elog_init(void);
void elog_set_output_enabled(bool_t enabled); void elog_set_output_enabled(bool enabled);
bool_t elog_get_output_enabled(void); bool elog_get_output_enabled(void);
void elog_set_fmt(size_t set); void elog_set_fmt(size_t set);
void elog_set_filter(uint8_t level, const char *tag, const char *keyword); void elog_set_filter(uint8_t level, const char *tag, const char *keyword);
void elog_set_filter_lvl(uint8_t level); void elog_set_filter_lvl(uint8_t level);

View File

@ -36,7 +36,7 @@ typedef struct {
typedef struct { typedef struct {
ElogFilter filter; ElogFilter filter;
size_t enabled_fmt_set; size_t enabled_fmt_set;
bool_t output_enabled; bool output_enabled;
}EasyLogger, *EasyLogger_t; }EasyLogger, *EasyLogger_t;
/* EasyLogger object */ /* EasyLogger object */
@ -54,7 +54,7 @@ static const char *level_output_info[] = {
"D/", "D/",
"V/", "V/",
}; };
static bool_t get_fmt_enabled(size_t set); static bool get_fmt_enabled(size_t set);
/** /**
* EasyLogger initialize. * EasyLogger initialize.
@ -69,7 +69,7 @@ ElogErrCode elog_init(void) {
/* set level is ELOG_LVL_VERBOSE */ /* set level is ELOG_LVL_VERBOSE */
elog_set_filter_lvl(ELOG_LVL_VERBOSE); elog_set_filter_lvl(ELOG_LVL_VERBOSE);
/* enable output */ /* enable output */
elog_set_output_enabled(TRUE); elog_set_output_enabled(true);
if (result == ELOG_NO_ERR) { if (result == ELOG_NO_ERR) {
elog_d(tag, "EasyLogger V%s is initialize success.", ELOG_SW_VERSION); elog_d(tag, "EasyLogger V%s is initialize success.", ELOG_SW_VERSION);
@ -84,8 +84,8 @@ ElogErrCode elog_init(void) {
* *
* @param enabled TRUE: enable FALSE: disable * @param enabled TRUE: enable FALSE: disable
*/ */
void elog_set_output_enabled(bool_t enabled) { void elog_set_output_enabled(bool enabled) {
ELOG_ASSERT((enabled == FALSE) || (enabled == TRUE)); ELOG_ASSERT((enabled == false) || (enabled == true));
elog.output_enabled = enabled; elog.output_enabled = enabled;
} }
@ -95,7 +95,7 @@ void elog_set_output_enabled(bool_t enabled) {
* *
* @return enable or disable * @return enable or disable
*/ */
bool_t elog_get_output_enabled(void) { bool elog_get_output_enabled(void) {
return elog.output_enabled; return elog.output_enabled;
} }
@ -303,7 +303,7 @@ void elog_output(uint8_t level, const char *tag, const char *file, const char *f
log_len += elog_strcpy(log_len, log_buf + log_len, ": "); log_len += elog_strcpy(log_len, log_buf + log_len, ": ");
} }
/* package other log data to buffer. CRLF length is 2. '\0' must be add in the end. */ /* package other log data to buffer. CRLF length is 2. '\0' must be added in the end by vsnprintf. */
fmt_result = vsnprintf(log_buf + log_len, ELOG_BUF_SIZE - log_len - 2 + 1, format, args); fmt_result = vsnprintf(log_buf + log_len, ELOG_BUF_SIZE - log_len - 2 + 1, format, args);
va_end(args); va_end(args);
@ -319,11 +319,9 @@ void elog_output(uint8_t level, const char *tag, const char *file, const char *f
/* package CRLF */ /* package CRLF */
if ((fmt_result > -1) && (fmt_result + log_len + 2 <= ELOG_BUF_SIZE)) { if ((fmt_result > -1) && (fmt_result + log_len + 2 <= ELOG_BUF_SIZE)) {
log_len += fmt_result; log_len += fmt_result;
/* add CRLF, cut the '\0' */
log_len += elog_strcpy(log_len, log_buf + log_len, "\r\n"); log_len += elog_strcpy(log_len, log_buf + log_len, "\r\n");
} else { } else {
/* add CRLF */
log_buf[ELOG_BUF_SIZE - 2] = '\r'; log_buf[ELOG_BUF_SIZE - 2] = '\r';
log_buf[ELOG_BUF_SIZE - 1] = '\n'; log_buf[ELOG_BUF_SIZE - 1] = '\n';
} }
@ -342,10 +340,10 @@ void elog_output(uint8_t level, const char *tag, const char *file, const char *f
* *
* @return enable or disable * @return enable or disable
*/ */
static bool_t get_fmt_enabled(size_t set) { static bool get_fmt_enabled(size_t set) {
if (elog.enabled_fmt_set & set) { if (elog.enabled_fmt_set & set) {
return TRUE; return true;
} else { } else {
return FALSE; return false;
} }
} }