Skip to content

Commit b07bd6c

Browse files
committed
[Utilities] Add more options for logtrace.
1 parent 09f2d42 commit b07bd6c

File tree

5 files changed

+145
-11
lines changed

5 files changed

+145
-11
lines changed

components/utilities/Kconfig

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,44 @@ config RT_USING_LOGTRACE
44
bool "Enable log trace"
55
default n
66

7+
if RT_USING_LOGTRACE
8+
config LOG_TRACE_MAX_SESSION
9+
int "Maximal number of session"
10+
default 16
11+
12+
choice
13+
prompt "The default level of log"
14+
default LOG_TRACE_USING_LEVEL_INFO
15+
16+
config LOG_TRACE_USING_LEVEL_NOTRACE
17+
bool "No trace"
18+
19+
config LOG_TRACE_USING_LEVEL_ERROR
20+
bool "Only error log"
21+
22+
config LOG_TRACE_USING_LEVEL_WARNING
23+
bool "Warning log"
24+
25+
config LOG_TRACE_USING_LEVEL_INFO
26+
bool "Information log"
27+
28+
config LOG_TRACE_USING_LEVEL_VERBOSE
29+
bool "Verbose log"
30+
31+
config LOG_TRACE_USING_LEVEL_DEBUG
32+
bool "All debug log"
33+
endchoice
34+
35+
config LOG_TRACE_USING_MEMLOG
36+
bool "Enable memory log for logtrace"
37+
default n
38+
help
39+
Enable memory log for logtrace, then the logs in log_trace
40+
will be printed out in idle thread hook function.
41+
42+
Please make sure the idle hook is not used.
43+
endif
44+
745
config RT_USING_RYM
846
bool "Enable Ymodem"
947
default n
Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
from building import *
22

33
cwd = GetCurrentDir()
4-
src = Glob('*.c')
4+
src = Split('''
5+
log_trace.c
6+
''')
57
CPPPATH = [cwd]
68

9+
if GetDepend('LOG_TRACE_USING_MEMLOG'):
10+
src += ['memlog.c']
11+
12+
if GetDepend('RT_USING_DFS'):
13+
src += ['log_file.c']
14+
715
group = DefineGroup('Utilities', src, depend = ['RT_USING_LOGTRACE'], CPPPATH = CPPPATH)
816

917
Return('group')

components/utilities/logtrace/log_trace.c

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ static struct rt_device _log_device;
4141
static rt_device_t _traceout_device = RT_NULL;
4242

4343
/* define a default lg session. The name is empty. */
44-
static struct log_trace_session _def_session = {{"\0"}, LOG_TRACE_LEVEL_INFO};
44+
static struct log_trace_session _def_session = {{"\0"}, LOG_TRACE_LEVEL_DEFAULT};
4545
static const struct log_trace_session *_the_sessions[LOG_TRACE_MAX_SESSION] = {&_def_session};
4646
/* there is a default session at least */
4747
static rt_uint16_t _the_sess_nr = 1;
@@ -267,16 +267,31 @@ void __logtrace_vfmtout(const struct log_trace_session *session,
267267
RT_ASSERT(session);
268268
RT_ASSERT(fmt);
269269

270-
rt_snprintf(_trace_buf, sizeof(_trace_buf), "[%08x][", rt_tick_get());
271-
if (_traceout_device != RT_NULL)
270+
/* it's default session */
271+
if (session->id.name[0] == '\0')
272272
{
273-
rt_device_write(_traceout_device, -1, _trace_buf, 11);
274-
rt_device_write(_traceout_device, -1,
275-
session->id.name, _idname_len(session->id.num));
273+
rt_snprintf(_trace_buf, sizeof(_trace_buf), "[%08x]", rt_tick_get());
274+
if (_traceout_device != RT_NULL)
275+
{
276+
rt_device_write(_traceout_device, -1, _trace_buf, 10);
277+
}
278+
279+
ptr = &_trace_buf[0];
280+
}
281+
else
282+
{
283+
rt_snprintf(_trace_buf, sizeof(_trace_buf), "[%08x][", rt_tick_get());
284+
if (_traceout_device != RT_NULL)
285+
{
286+
rt_device_write(_traceout_device, -1, _trace_buf, 11);
287+
rt_device_write(_traceout_device, -1,
288+
session->id.name, _idname_len(session->id.num));
289+
}
290+
291+
_trace_buf[0] = ']';
292+
ptr = &_trace_buf[1];
276293
}
277294

278-
_trace_buf[0] = ']';
279-
ptr = &_trace_buf[1];
280295
length = rt_vsnprintf(ptr, LOG_TRACE_BUFSZ, fmt, argptr);
281296

282297
if (length >= LOG_TRACE_BUFSZ)

components/utilities/logtrace/log_trace.h

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,20 @@
3737
#define LOG_TRACE_LEVEL_DEBUG 0x09
3838
#define LOG_TRACE_LEVEL_ALL 0x0f
3939

40-
#ifndef LOG_TRACE_LEVEL_DEFAULT
41-
#define LOG_TRACE_LEVEL_DEFAULT LOG_TRACE_LEVEL_INFO
40+
#if defined(LOG_TRACE_USING_LEVEL_NOTRACE)
41+
#define LOG_TRACE_LEVEL_DEFAULT LOG_TRACE_LEVEL_NOTRACE
42+
#elif defined(LOG_TRACE_USING_LEVEL_ERROR)
43+
#define LOG_TRACE_LEVEL_DEFAULT LOG_TRACE_LEVEL_ERROR
44+
#elif defined(LOG_TRACE_USING_LEVEL_WARNING)
45+
#define LOG_TRACE_LEVEL_DEFAULT LOG_TRACE_LEVEL_WARNING
46+
#elif defined(LOG_TRACE_USING_LEVEL_INFO)
47+
#define LOG_TRACE_LEVEL_DEFAULT LOG_TRACE_LEVEL_INFO
48+
#elif defined(LOG_TRACE_USING_LEVEL_VERBOSE)
49+
#define LOG_TRACE_LEVEL_DEFAULT LOG_TRACE_LEVEL_VERBOSE
50+
#elif defined(LOG_TRACE_USING_LEVEL_DEBUG)
51+
#define LOG_TRACE_LEVEL_DEFAULT LOG_TRACE_LEVEL_DEBUG
52+
#else
53+
#define LOG_TRACE_LEVEL_DEFAULT LOG_TRACE_LEVEL_INFO
4254
#endif
4355

4456
#define LOG_TRACE_ERROR "<1>"
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* File : memlog.c
3+
* This file is part of RT-Thread RTOS
4+
* COPYRIGHT (C) 2013, RT-Thread Development Team
5+
*
6+
* This program is free software; you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation; either version 2 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License along
17+
* with this program; if not, write to the Free Software Foundation, Inc.,
18+
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19+
*
20+
* Change Logs:
21+
* Date Author Notes
22+
* 2013-06-26 Grissiom the first version
23+
*/
24+
25+
#include <rtthread.h>
26+
#include <rtdevice.h>
27+
#include <log_trace.h>
28+
29+
#define PIPE_SZ 2048
30+
#define PIPE_NAME "memlog"
31+
32+
static rt_pipe_t *_log_pipe = NULL;
33+
static rt_uint8_t outbuf[1024];
34+
void memlog_flush(void)
35+
{
36+
rt_size_t readsz;
37+
rt_device_t console;
38+
39+
console = rt_console_get_device();
40+
if (!console) return;
41+
42+
readsz = rt_device_read((rt_device_t)&(_log_pipe->parent), 0, outbuf, sizeof(outbuf));
43+
if (readsz)
44+
rt_device_write(console, 0, outbuf, readsz);
45+
}
46+
47+
int memlog_init(void)
48+
{
49+
_log_pipe = rt_pipe_create(PIPE_NAME, PIPE_SZ);
50+
if (_log_pipe == RT_NULL)
51+
{
52+
rt_kprintf("init pipe device failed.\n");
53+
return -1;
54+
}
55+
56+
log_trace_set_device(PIPE_NAME);
57+
rt_thread_idle_sethook(memlog_flush);
58+
59+
return 0;
60+
}
61+
INIT_APP_EXPORT(memlog_init);

0 commit comments

Comments
 (0)