2021-01-07 19:01:08 +08:00
|
|
|
/*
|
|
|
|
* @Description:
|
|
|
|
* @Date: 2020-12-22 18:27:24
|
|
|
|
* @LastEditors: CK.Zh
|
|
|
|
* @LastEditTime: 2021-01-07 17:54:00
|
|
|
|
* @FilePath: \NaviKit_stm32\Middlewares\Log\log.c
|
|
|
|
*/
|
2020-12-17 18:22:19 +08:00
|
|
|
/*
|
|
|
|
* log.c
|
|
|
|
*
|
|
|
|
* Created on: Dec 16, 2020
|
|
|
|
* Author: bookshiyi
|
|
|
|
*/
|
|
|
|
#include "log.h"
|
|
|
|
|
2021-01-07 19:01:08 +08:00
|
|
|
static bool mutex =false;
|
2020-12-17 18:22:19 +08:00
|
|
|
|
2021-01-07 19:01:08 +08:00
|
|
|
void Log(LogLevel_t level,LogPositon_t positon,char *format,...)
|
2020-12-17 18:22:19 +08:00
|
|
|
{
|
2021-01-07 19:01:08 +08:00
|
|
|
if(mutex){
|
|
|
|
unsigned char time_out = 100;
|
|
|
|
while(mutex && time_out--){//100ms timout for multi-thread use log function
|
|
|
|
osDelay(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!mutex){
|
|
|
|
mutex = true;
|
|
|
|
|
|
|
|
switch(level){
|
|
|
|
case trace: { printf("[Trace ] ") ; }break;
|
|
|
|
case debug: { printf("[Debug ] ") ; }break;
|
|
|
|
case info: { printf("[Info ] ") ; }break;
|
|
|
|
case warning:{ printf("[Warning] ") ; }break;
|
|
|
|
case error: { printf("[Error ] ") ; }break;
|
|
|
|
case fatal: { printf("[Fatal ] ") ; }break;
|
|
|
|
default: { printf("[Undefined Level] ") ; }break;
|
|
|
|
}
|
|
|
|
switch (positon)
|
|
|
|
{
|
|
|
|
case sys:{ printf("SYS: ") ; }break;
|
|
|
|
case som:{ printf("SOM: ") ; }break;
|
|
|
|
case pmb:{ printf("PMB: ") ; }break;
|
|
|
|
default: { printf("Undefined Position: ") ;}break;
|
2020-12-17 18:22:19 +08:00
|
|
|
}
|
2021-02-19 09:44:30 +08:00
|
|
|
printf("%8u | ",osKernelGetTickCount());
|
2020-12-17 18:22:19 +08:00
|
|
|
va_list args;
|
|
|
|
va_start( args, format );
|
|
|
|
print(0, format, args );
|
|
|
|
printf("\n") ;
|
2021-01-07 19:01:08 +08:00
|
|
|
|
|
|
|
mutex = false;
|
|
|
|
}
|
2020-12-17 18:22:19 +08:00
|
|
|
}
|
|
|
|
|