Files
OpenCellular/firmware/host/include/logger.h
swateeshrivastava 8a070266a5 Host code for alert
2019-03-04 15:27:40 +05:30

82 lines
3.9 KiB
C

/**
* 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 <syslog.h>
#include <libgen.h>
#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, "<d> [%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, "<E> " fmt, ##__VA_ARGS__)
#define logalert(fmt, ...) logit(LOG_ALERT, "<A> " fmt, ##__VA_ARGS__)
#define logcrit(fmt, ...) logit(LOG_CRIT, "<C> " fmt, ##__VA_ARGS__)
#define logerr(fmt, ...) logit(LOG_ERR, "<e> " fmt, ##__VA_ARGS__)
#define logwarn(fmt, ...) logit(LOG_WARNING, "<w> " fmt, ##__VA_ARGS__)
#define lognotice(fmt, ...) logit(LOG_NOTICE, "<n> " fmt, ##__VA_ARGS__)
#define loginfo(fmt, ...) logit(LOG_INFO, "<i> " 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__ */