Browse Source

【存在问题】日志写文件

paint_robot_new-v1.5
Lizongdi 2 weeks ago
parent
commit
53d486f9e0
  1. 10
      library/log/elog_port.c
  2. 2
      library/log/include/elog_file.h
  3. 2
      library/log/include/elog_file_cfg.h
  4. 8
      library/log/log.c

10
library/log/elog_port.c

@ -35,9 +35,7 @@
#include "rd_time.h" #include "rd_time.h"
#include "rd_thread.h" #include "rd_thread.h"
#ifndef DEBUG
#include "elog_file.h" #include "elog_file.h"
#endif
static pthread_mutex_t output_lock; static pthread_mutex_t output_lock;
@ -49,9 +47,7 @@ static pthread_mutex_t output_lock;
WEAK ElogErrCode elog_port_init(void) { WEAK ElogErrCode elog_port_init(void) {
ElogErrCode result = ELOG_NO_ERR; ElogErrCode result = ELOG_NO_ERR;
Rd_MutexInit(&output_lock); Rd_MutexInit(&output_lock);
#ifndef DEBUG
elog_file_init(); elog_file_init();
#endif
return result; return result;
} }
@ -60,9 +56,7 @@ WEAK ElogErrCode elog_port_init(void) {
* *
*/ */
WEAK void elog_port_deinit(void) { WEAK void elog_port_deinit(void) {
#ifndef DEBUG
elog_file_deinit(); elog_file_deinit();
#endif
Rd_MutexDestroy(&output_lock); Rd_MutexDestroy(&output_lock);
} }
@ -73,11 +67,7 @@ WEAK void elog_port_deinit(void) {
* @param size log size * @param size log size
*/ */
WEAK void elog_port_output(const char *log, size_t size) { WEAK void elog_port_output(const char *log, size_t size) {
#ifdef DEBUG
RD_PRINTF("%.*s", (int)size, log);
#else
elog_file_write(log, size); elog_file_write(log, size);
#endif
} }
/** /**

2
library/log/include/elog_file.h

@ -38,9 +38,7 @@
extern "C" { extern "C" {
#endif #endif
#ifndef DEBUG
#define ELOG_FILE_ENABLE #define ELOG_FILE_ENABLE
#endif
/* EasyLogger file log plugin's software version number */ /* EasyLogger file log plugin's software version number */
#define ELOG_FILE_SW_VERSION "V1.0.0" #define ELOG_FILE_SW_VERSION "V1.0.0"

2
library/log/include/elog_file_cfg.h

@ -31,7 +31,7 @@
#define _ELOG_FILE_CFG_H_ #define _ELOG_FILE_CFG_H_
/* EasyLogger file log plugin's using file name */ /* EasyLogger file log plugin's using file name */
#define ELOG_FILE_NAME "rd.log" #define ELOG_FILE_NAME "C:rd.log"
/* EasyLogger file log plugin's using file max size */ /* EasyLogger file log plugin's using file max size */
#define ELOG_FILE_MAX_SIZE (1 * 1024 * 1024) #define ELOG_FILE_MAX_SIZE (1 * 1024 * 1024)

8
library/log/log.c

@ -1,18 +1,10 @@
#include <stdio.h> #include <stdio.h>
#include "elog.h" #include "elog.h"
void Rd_ElogEnableStrong(void)
{
// 用于强符号覆盖的锚点
}
__attribute__((constructor(101)))
void Rd_ElogInit(void) void Rd_ElogInit(void)
{ {
#ifndef DEBUG
/* close printf buffer */ /* close printf buffer */
//setbuf(stdout, NULL); //setbuf(stdout, NULL);
#endif
/* initialize EasyLogger */ /* initialize EasyLogger */
elog_init(); elog_init();
/* set EasyLogger log format */ /* set EasyLogger log format */

Loading…
Cancel
Save