/** * Copyright (c) 2017-present, Facebook, Inc. * All rights reserved. * * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. An additional grant * of patent rights can be found in the PATENTS file in the same directory. */ #ifndef __LOGGER_H__ #define __LOGGER_H__ #include #include #define __filename__ (basename(__FILE__)) #ifdef CONSOLE_LOG # define logit(facility, fmt, ...) \ { \ if (facility != LOG_DEBUG) \ printf(fmt "\n", ##__VA_ARGS__); \ else \ printf("[%s:%d, %s()]:" fmt "\n", __filename__, __LINE__, \ __func__, ##__VA_ARGS__); \ } #elif SYS_LOG /* syslog */ # define logit(facility, fmt, ...) \ { \ if (facility != LOG_DEBUG) \ syslog(facility, fmt "\n", ##__VA_ARGS__); \ else \ syslog(facility, " [%s:%d, %s()]: " fmt "\n", __filename__, \ __LINE__, __func__, ##__VA_ARGS__); \ } #elif OCCLI_LOG # define logit(facility, fmt, ...) \ { \ FILE *fp; \ fp = fopen("./log/logFileOccli.txt", "a"); \ if (facility != LOG_DEBUG) \ fprintf(fp, fmt "\n", ##__VA_ARGS__); \ else \ fprintf(fp, "[%s:%d, %s()]:" fmt "\n", __filename__, __LINE__, \ __func__, ##__VA_ARGS__); \ fclose(fp); \ } #else # define logit(facility, fmt, ...) \ { \ FILE *fp; \ fp = fopen("./log/logFileMW.txt", "a"); \ if (facility != LOG_DEBUG) \ fprintf(fp, fmt "\n", ##__VA_ARGS__); \ else \ fprintf(fp, "[%s:%d, %s()]:" fmt "\n", __filename__, __LINE__, \ __func__, ##__VA_ARGS__); \ fclose(fp); \ } #endif #define logemerg(fmt, ...) logit(LOG_EMERG, " " fmt, ##__VA_ARGS__) #define logalert(fmt, ...) logit(LOG_ALERT, " " fmt, ##__VA_ARGS__) #define logcrit(fmt, ...) logit(LOG_CRIT, " " fmt, ##__VA_ARGS__) #define logerr(fmt, ...) logit(LOG_ERR, " " fmt, ##__VA_ARGS__) #define logwarn(fmt, ...) logit(LOG_WARNING, " " fmt, ##__VA_ARGS__) #define lognotice(fmt, ...) logit(LOG_NOTICE, " " fmt, ##__VA_ARGS__) #define loginfo(fmt, ...) logit(LOG_INFO, " " fmt, ##__VA_ARGS__) #define logdebug(fmt, ...) logit(LOG_DEBUG, fmt, ##__VA_ARGS__) /* * @param ident an input value (by pointer) * */ extern void initlog(const char *ident); /* * deinitialize the logging routine * */ extern void deinitlog(void); #endif /* __LOGGER_H__ */