44 lines
1.1 KiB
C
44 lines
1.1 KiB
C
![]() |
#ifndef __LOG_H__
|
||
|
#define __LOG_H__
|
||
|
|
||
|
#include <stdio.h>
|
||
|
#include <time.h>
|
||
|
#include <stdarg.h>
|
||
|
#include <errno.h>
|
||
|
#include "typeorigin.h"
|
||
|
|
||
|
#ifdef linux
|
||
|
|
||
|
// log print with time
|
||
|
#define LOG_PRINT_TIME(fmt, ...) \
|
||
|
do { \
|
||
|
time_t t = time(NULL); \
|
||
|
struct tm *tm_info = localtime(&t); \
|
||
|
char buffer[26]; \
|
||
|
strftime(buffer, 26, "%Y-%m-%d %H:%M:%S", tm_info); \
|
||
|
printf("[%s]: " fmt, buffer, ##__VA_ARGS__); \
|
||
|
} while (0)
|
||
|
|
||
|
// log print with time and file name
|
||
|
#define LOG_PRINT_ERROR(fmt, ...) \
|
||
|
do { \
|
||
|
time_t t = time(NULL); \
|
||
|
struct tm *tm_info = localtime(&t); \
|
||
|
char buffer[26]; \
|
||
|
strftime(buffer, 26, "%Y-%m-%d %H:%M:%S", tm_info); \
|
||
|
printf("[%s] %s:%s:%d: " fmt, buffer, __FILE__, __FUNCTION__, __LINE__, ##__VA_ARGS__); \
|
||
|
} while (0)
|
||
|
|
||
|
// log print without time
|
||
|
#define LOG_PRINT(fmt, ...) \
|
||
|
do { \
|
||
|
printf(fmt, ##__VA_ARGS__); \
|
||
|
} while (0)
|
||
|
|
||
|
#else
|
||
|
#define LOG_PRINT_TIME(fmt, ...) printf(fmt, ##__VA_ARGS__)
|
||
|
#define LOG_PRINT_ERROR(fmt, ...) printf(fmt, ##__VA_ARGS__)
|
||
|
#define LOG_PRINT(fmt, ...) printf(fmt, ##__VA_ARGS__)
|
||
|
#endif
|
||
|
|
||
|
#endif
|