1、【删除】日志输出的结束符'\0'。

Signed-off-by: armink <armink.ztl@gmail.com>
pull/3/head
armink 11 years ago
parent f6fdac529d
commit ccd4fd8520

@ -16,7 +16,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
* *
* Function: Portable interface for each platform. * Function: Portable interface for RT-Thread.
* Created on: 2015-04-28 * Created on: 2015-04-28
*/ */
@ -44,7 +44,7 @@ ElogErrCode elog_port_init(void) {
*/ */
void elog_port_output(const char *output, size_t size) { void elog_port_output(const char *output, size_t size) {
/* output to terminal */ /* output to terminal */
rt_kprintf("%s", output); rt_kprintf("%.*s", size, output);
//TODO output to flash //TODO output to flash
} }

@ -47,7 +47,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.10" #define ELOG_SW_VERSION "0.05.15"
/* EasyLogger assert for developer. */ /* EasyLogger assert for developer. */
#define ELOG_ASSERT(EXPR) \ #define ELOG_ASSERT(EXPR) \

@ -240,8 +240,8 @@ 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, tag); log_len += elog_strcpy(log_len, log_buf + log_len, tag);
/* if the tag length is less than 50% ELOG_FILTER_TAG_MAX_LEN, then fill space */ /* if the tag length is less than 50% ELOG_FILTER_TAG_MAX_LEN, then fill space */
if (tag_len <= ELOG_FILTER_TAG_MAX_LEN / 2) { if (tag_len <= ELOG_FILTER_TAG_MAX_LEN / 2) {
memset(tag_sapce, ' ', ELOG_FILTER_TAG_MAX_LEN / 2 - tag_len); memset(tag_sapce, ' ', ELOG_FILTER_TAG_MAX_LEN / 2 - tag_len);
log_len += elog_strcpy(log_len, log_buf + log_len, tag_sapce); log_len += elog_strcpy(log_len, log_buf + log_len, tag_sapce);
} }
log_len += elog_strcpy(log_len, log_buf + log_len, " "); log_len += elog_strcpy(log_len, log_buf + log_len, " ");
} }
@ -303,8 +303,8 @@ 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. */ /* package other log data to buffer. CRLF length is 2. '\0' must be add in the end. */
fmt_result = vsnprintf(log_buf + log_len, ELOG_BUF_SIZE - log_len - 2, format, args); fmt_result = vsnprintf(log_buf + log_len, ELOG_BUF_SIZE - log_len - 2 + 1, format, args);
va_end(args); va_end(args);
@ -316,20 +316,16 @@ void elog_output(uint8_t level, const char *tag, const char *file, const char *f
return; return;
} }
/* package end sign( CRLF and '\0' ) */ /* 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 */ /* 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");
/* add '\0' */
log_buf[log_len++] = '\0';
} else { } else {
/* add CRLF */ /* add CRLF */
log_buf[ELOG_BUF_SIZE - 3] = '\r'; log_buf[ELOG_BUF_SIZE - 2] = '\r';
log_buf[ELOG_BUF_SIZE - 2] = '\n'; log_buf[ELOG_BUF_SIZE - 1] = '\n';
/* add log end sign */
log_buf[ELOG_BUF_SIZE - 1] = '\0';
} }
/* output log */ /* output log */

@ -35,7 +35,7 @@ size_t elog_strcpy(size_t cur_len, char *dst, const char *src) {
const char *src_old = src; const char *src_old = src;
while (*src != 0) { while (*src != 0) {
/* make sure destination has enough space */ /* make sure destination has enough space */
if (cur_len++ < ELOG_BUF_SIZE) { if (cur_len++ <= ELOG_BUF_SIZE) {
*dst++ = *src++; *dst++ = *src++;
} else { } else {
break; break;

Loading…
Cancel
Save