Skip to content

Commit

Permalink
* NEW support to print log to file.
Browse files Browse the repository at this point in the history
  • Loading branch information
wanghaEMQ committed Nov 17, 2023
1 parent bca4f8c commit 0116a94
Showing 1 changed file with 65 additions and 19 deletions.
84 changes: 65 additions & 19 deletions src/log4nftp.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,43 +18,89 @@
#ifndef DEBUG
#define nftp_fatal(format, ...) \
do { \
fprintf(stderr, "%s:%d(%s) " format "\n", __FILE__, __LINE__, \
fprintf(stderr, "ERR %s:%d(%s) " format "\n", __FILE__, __LINE__, \
__FUNCTION__, __VA_ARGS__); \
} while (0)
#else
// Only EXIT in DEBUG MODE
#else //DEBUG
#ifdef LOGTOFILE
#define nftp_fatal(format, ...) \
do { \
fprintf(stderr, "%s:%d(%s) " format "\n", __FILE__, __LINE__, \
FILE *fd = fopen(LOGTOFILE, "w"); \
fprintf(fd, "ERR %s:%d(%s) " format "\n", __FILE__, __LINE__, \
__FUNCTION__, __VA_ARGS__); \
exit(0); \
fclose(fd); \
} while (0)
#endif
#else
#else // LOGTOFILE
do { \
fprintf(stderr, "ERR %s:%d(%s) " format "\n", __FILE__, __LINE__, \
__FUNCTION__, __VA_ARGS__); \
} while (0)
#endif // LOGTOFILE
#endif // DEBUG
#else // LINUX
#ifndef DEBUG
#define nftp_fatal(format, arg...) \
do { \
fprintf(stderr, "%s:%d(%s) " format "\n", __FILE__, __LINE__, \
fprintf(stderr, "ERR %s:%d(%s) " format "\n", __FILE__, __LINE__, \
__FUNCTION__, ##arg); \
} while (0)
#else
// Only EXIT in DEBUG MODE
#else // DEBUG
#ifdef LOGTOFILE
#define nftp_fatal(format, arg...) \
do { \
fprintf(stderr, "%s:%d(%s) " format "\n", __FILE__, __LINE__, \
FILE *fd = fopen(LOGTOFILE, "w"); \
fprintf(fd, "ERR %s:%d(%s) " format "\n", __FILE__, __LINE__, \
__FUNCTION__, ##arg); \
fclose(fd); \
} while (0)
#endif
#endif
#else // LOGTOFILE
#define nftp_fatal(format, arg...) \
do { \
fprintf(stderr, "ERR %s:%d(%s) " format "\n", __FILE__, __LINE__, \
__FUNCTION__, ##arg); \
} while (0)
#endif // LOGTOFILE
#endif // DEBUG
#endif // WIN32

#ifdef _WIN32
#ifdef DEBUG
#ifdef LOGTOFILE
#define nftp_log(format, ...) \
fprintf(stderr, "%s:%d(%s) " format "\n", __FILE__, __LINE__, \
__FUNCTION__, __VA_ARGS__)
#else
do { \
FILE *fd = fopen(LOGTOFILE, "w"); \
fprintf(fd, "INFO %s:%d(%s) " format "\n", __FILE__, __LINE__, \
__FUNCTION__, __VA_ARGS__); \
fclose(fd); \
} while (0)
#else // LOGTOFILE
#define nftp_log(format, ...) \
do { \
fprintf(stderr, "INFO %s:%d(%s) " format "\n", __FILE__, __LINE__, \
__FUNCTION__, __VA_ARGS__); \
} while (0)
#endif // LOGTOFILE
#endif // DEBUG

#else // Linux

#ifdef DEBUG
#ifdef LOGTOFILE
#define nftp_log(format, arg...) \
fprintf(stderr, "%s:%d(%s) " format "\n", __FILE__, __LINE__, \
__FUNCTION__, ##arg)
#endif
do { \
FILE *fd = fopen(LOGTOFILE, "w"); \
fprintf(fd, "INFO %s:%d(%s) " format "\n", __FILE__, __LINE__, \
__FUNCTION__, ##arg); \
fclose(fd); \
} while (0)
#else // LOGTOFILE
#define nftp_log(format, arg...) \
do { \
fprintf(stderr, "INFO %s:%d(%s) " format "\n", __FILE__, __LINE__, \
__FUNCTION__, ##arg); \
} while (0)
#endif // LOGTOFILE
#endif // DEBUG
#endif // WIN32

#endif

0 comments on commit 0116a94

Please sign in to comment.