提交 b07bd6c5 编写于 作者: B bernard

[Utilities] Add more options for logtrace.

上级 09f2d42e
......@@ -4,6 +4,44 @@ config RT_USING_LOGTRACE
bool "Enable log trace"
default n
if RT_USING_LOGTRACE
config LOG_TRACE_MAX_SESSION
int "Maximal number of session"
default 16
choice
prompt "The default level of log"
default LOG_TRACE_USING_LEVEL_INFO
config LOG_TRACE_USING_LEVEL_NOTRACE
bool "No trace"
config LOG_TRACE_USING_LEVEL_ERROR
bool "Only error log"
config LOG_TRACE_USING_LEVEL_WARNING
bool "Warning log"
config LOG_TRACE_USING_LEVEL_INFO
bool "Information log"
config LOG_TRACE_USING_LEVEL_VERBOSE
bool "Verbose log"
config LOG_TRACE_USING_LEVEL_DEBUG
bool "All debug log"
endchoice
config LOG_TRACE_USING_MEMLOG
bool "Enable memory log for logtrace"
default n
help
Enable memory log for logtrace, then the logs in log_trace
will be printed out in idle thread hook function.
Please make sure the idle hook is not used.
endif
config RT_USING_RYM
bool "Enable Ymodem"
default n
......
from building import *
cwd = GetCurrentDir()
src = Glob('*.c')
src = Split('''
log_trace.c
''')
CPPPATH = [cwd]
if GetDepend('LOG_TRACE_USING_MEMLOG'):
src += ['memlog.c']
if GetDepend('RT_USING_DFS'):
src += ['log_file.c']
group = DefineGroup('Utilities', src, depend = ['RT_USING_LOGTRACE'], CPPPATH = CPPPATH)
Return('group')
......@@ -41,7 +41,7 @@ static struct rt_device _log_device;
static rt_device_t _traceout_device = RT_NULL;
/* define a default lg session. The name is empty. */
static struct log_trace_session _def_session = {{"\0"}, LOG_TRACE_LEVEL_INFO};
static struct log_trace_session _def_session = {{"\0"}, LOG_TRACE_LEVEL_DEFAULT};
static const struct log_trace_session *_the_sessions[LOG_TRACE_MAX_SESSION] = {&_def_session};
/* there is a default session at least */
static rt_uint16_t _the_sess_nr = 1;
......@@ -267,16 +267,31 @@ void __logtrace_vfmtout(const struct log_trace_session *session,
RT_ASSERT(session);
RT_ASSERT(fmt);
rt_snprintf(_trace_buf, sizeof(_trace_buf), "[%08x][", rt_tick_get());
if (_traceout_device != RT_NULL)
/* it's default session */
if (session->id.name[0] == '\0')
{
rt_device_write(_traceout_device, -1, _trace_buf, 11);
rt_device_write(_traceout_device, -1,
session->id.name, _idname_len(session->id.num));
rt_snprintf(_trace_buf, sizeof(_trace_buf), "[%08x]", rt_tick_get());
if (_traceout_device != RT_NULL)
{
rt_device_write(_traceout_device, -1, _trace_buf, 10);
}
ptr = &_trace_buf[0];
}
else
{
rt_snprintf(_trace_buf, sizeof(_trace_buf), "[%08x][", rt_tick_get());
if (_traceout_device != RT_NULL)
{
rt_device_write(_traceout_device, -1, _trace_buf, 11);
rt_device_write(_traceout_device, -1,
session->id.name, _idname_len(session->id.num));
}
_trace_buf[0] = ']';
ptr = &_trace_buf[1];
}
_trace_buf[0] = ']';
ptr = &_trace_buf[1];
length = rt_vsnprintf(ptr, LOG_TRACE_BUFSZ, fmt, argptr);
if (length >= LOG_TRACE_BUFSZ)
......
......@@ -37,8 +37,20 @@
#define LOG_TRACE_LEVEL_DEBUG 0x09
#define LOG_TRACE_LEVEL_ALL 0x0f
#ifndef LOG_TRACE_LEVEL_DEFAULT
#define LOG_TRACE_LEVEL_DEFAULT LOG_TRACE_LEVEL_INFO
#if defined(LOG_TRACE_USING_LEVEL_NOTRACE)
#define LOG_TRACE_LEVEL_DEFAULT LOG_TRACE_LEVEL_NOTRACE
#elif defined(LOG_TRACE_USING_LEVEL_ERROR)
#define LOG_TRACE_LEVEL_DEFAULT LOG_TRACE_LEVEL_ERROR
#elif defined(LOG_TRACE_USING_LEVEL_WARNING)
#define LOG_TRACE_LEVEL_DEFAULT LOG_TRACE_LEVEL_WARNING
#elif defined(LOG_TRACE_USING_LEVEL_INFO)
#define LOG_TRACE_LEVEL_DEFAULT LOG_TRACE_LEVEL_INFO
#elif defined(LOG_TRACE_USING_LEVEL_VERBOSE)
#define LOG_TRACE_LEVEL_DEFAULT LOG_TRACE_LEVEL_VERBOSE
#elif defined(LOG_TRACE_USING_LEVEL_DEBUG)
#define LOG_TRACE_LEVEL_DEFAULT LOG_TRACE_LEVEL_DEBUG
#else
#define LOG_TRACE_LEVEL_DEFAULT LOG_TRACE_LEVEL_INFO
#endif
#define LOG_TRACE_ERROR "<1>"
......
/*
* File : memlog.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2013, RT-Thread Development Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
* 2013-06-26 Grissiom the first version
*/
#include <rtthread.h>
#include <rtdevice.h>
#include <log_trace.h>
#define PIPE_SZ 2048
#define PIPE_NAME "memlog"
static rt_pipe_t *_log_pipe = NULL;
static rt_uint8_t outbuf[1024];
void memlog_flush(void)
{
rt_size_t readsz;
rt_device_t console;
console = rt_console_get_device();
if (!console) return;
readsz = rt_device_read((rt_device_t)&(_log_pipe->parent), 0, outbuf, sizeof(outbuf));
if (readsz)
rt_device_write(console, 0, outbuf, readsz);
}
int memlog_init(void)
{
_log_pipe = rt_pipe_create(PIPE_NAME, PIPE_SZ);
if (_log_pipe == RT_NULL)
{
rt_kprintf("init pipe device failed.\n");
return -1;
}
log_trace_set_device(PIPE_NAME);
rt_thread_idle_sethook(memlog_flush);
return 0;
}
INIT_APP_EXPORT(memlog_init);
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册