| 12345678910111213141516171819202122232425262728293031323334353637 |
- #include <elog.h>
-
- static elog_t *logger;
- static char arena[1024];
-
- static void log_to_semihost(elog_entry_t *e, int len, void *ctx)
- {
- // 发送出去
- uint32_t *p = (void *)e;
- int num = len / sizeof(uint32_t);
- rt_kprintf("num:%d\n", num);
- rt_kprintf("len:%d\n", MSGPTR_LEN(p[0])); // 通过msg->id解出参数个数
-
- for(int i = 0; i < num; i++)
- {
- if(0 == i)
- {
- rt_kprintf("0x%08X ", MSGPTR_MSG(p[i])); // 通过msg_id解出参数内容
- continue;
- }
-
- rt_kprintf("%d ", p[i]);
- }
-
- rt_kprintf("\n\n");
- }
-
- int elog_test(void)
- {
- logger = elog_init(arena, sizeof(arena));
- ELOG(logger, "Hello world %d\n", 10); // 把字符串和参数放到内存中,(通过字符串 + 长度算法生成msg_id)和会形成一条msg_id和长度
- ELOG(logger, "test %d %d %c\n", 1, 2, 3);
- ELOG(logger, "no agrc test\n");
-
- elog_flush(logger, log_to_semihost, NULL); // 将内存中的日志刷新到文件,也可以是传输到上位机。也就是之前(字符串和参数)生成的msg_id和长度
- return 0;
- }
|