在朗讯的几年总是习惯通过log找程序问题;写了这个小小的跟踪模块。
还是非常ugly的,以后加入log level.
头文件:traceService.h
/*copyright [email protected] edit in 2010 */
#ifndef TRACESERVICE_H
#define TRACESERVICE_H#endif // TRACESERVICE_H
traceService.cpp
/*copyright [email protected] edit in 2010*/
#include "traceservice.h"
#include <string.h>
TraceService::TraceService(const unsigned int Line, const char * Function_Name,const char * File_name)
{
_m_line=Line;
_m_file_name = GetFileName(File_name);
_m_function_name= Function_Name;
printf("Enter function %-20s (%s, %d)\n",_m_function_name,_m_file_name,_m_line);
}
TraceService::~TraceService()
{
printf("Exit function %-20s (%s, %d)\n",_m_function_name,_m_file_name,_m_line);
}
char *GetFileName(const char *path)
{
char *p;
p=strrchr(path, '/');
if (p)
return p+1;
else
return NULL;
}
用法:
xxx.cpp
#include "traceService.h"
func1()
{
TRACE_SERVICE_ENTRY_EXIT();
..........
}
func2()
{
TRACE_SERVICE_ENTRY_EXIT();
.............
}