diff options
-rw-r--r-- | Makefile | 4 | ||||
-rw-r--r-- | debug.c | 26 | ||||
-rw-r--r-- | debug.h | 2 | ||||
-rw-r--r-- | main.c | 13 |
4 files changed, 37 insertions, 8 deletions
@@ -1,5 +1,5 @@ include Makefile.files all: - gcc ${DEBUG_SOURCES} main.c -o debug -# -DWITH_DBG_MUTEX
\ No newline at end of file + gcc ${DEBUG_SOURCES} main.c debug_syslog.c -o debug -DWITH_DBG_SYSLOG +# -DWITH_DBG_MUTEX @@ -48,6 +48,10 @@ struct { #endif int fd; int file_fd; +#ifdef WITH_DBG_SYSLOG + const char* syslog_host; + int syslog_port; +#endif } dbg_config = { .flags = DBG_FLAG_DEFAULT, .fd = -1, .file_fd = -1 }; static void dbg_mutex_init() @@ -114,6 +118,14 @@ dbg_status_t dbg_init(unsigned int flags, ...) dbg_config.file_fd = open(filename, O_CREAT | O_RDWR, 0777); } break; +#ifdef WITH_DBG_SYSLOG + case DBG_OPTION_SYSLOG_PORT: + dbg_config.syslog_port = va_arg(vl, int); + break; + case DBG_OPTION_SYSLOG_HOST: + dbg_config.syslog_host = (const char*)va_arg(vl, char*); + break; +#endif default: status = DBG_STATUS_UNKNOWN_OPTION; printf("option: %x\n", option); @@ -123,6 +135,12 @@ dbg_status_t dbg_init(unsigned int flags, ...) dbg_mutex_init(); +#ifdef WITH_DBG_SYSLOG + if(dbg_config.flags & DBG_FLAG_OUTPUT_TO_SYSLOG) { + dbg_syslog_init(dbg_config.syslog_host, dbg_config.syslog_port); + } +#endif + err: va_end(vl); @@ -135,6 +153,10 @@ void dbg_close() if(dbg_config.file_fd != -1) close(dbg_config.file_fd); } +#ifdef WITH_DBG_SYSLOG + dbg_syslog_close(); +#endif + dbg_mutex_close(); } @@ -212,6 +234,10 @@ int __debug(const char *func, const int line, dbg_output_fd(dbg_config.file_fd, buf); } + if(dbg_config.flags & DBG_FLAG_OUTPUT_TO_SYSLOG) { + dbg_syslog_output(buf); + } + done: dbg_mutex_unlock(); @@ -46,7 +46,7 @@ enum DBG_FLAG { DBG_FLAG_OUTPUT_TO_FD = 0x00040000, DBG_FLAG_OUTPUT_TO_FILE = 0x00080000, #ifdef WITH_DBG_SYSLOG - DBG_FLAG_OUTPUT_TO_SYSLOG = 0x000f0000, + DBG_FLAG_OUTPUT_TO_SYSLOG = 0x00100000, #endif // Default value of flags @@ -42,13 +42,18 @@ int main(int argc, char *argv[]) } */ dbg_status_t status = dbg_init(//DBG_FLAG_USE_MUTEX | - DBG_FLAG_OUTPUT_TO_FILE | + //DBG_FLAG_OUTPUT_TO_FILE | //DBG_FLAG_OUTPUT_TO_FD | - //DBG_FLAG_OUTPUT_TO_STDOUT | +// DBG_FLAG_OUTPUT_TO_STDOUT | + DBG_FLAG_OUTPUT_TO_SYSLOG | //DBG_FLAG_OUTPUT_TO_STDERR | 0, //DBG_OPTION_FD, fd, - DBG_OPTION_FILENAME, "/tmp/my2.log", +// DBG_OPTION_FILENAME, "", + DBG_OPTION_SYSLOG_HOST, + "127.0.0.1", + DBG_OPTION_SYSLOG_PORT, + 514, DBG_OPTION_END); if(status != DBG_STATUS_OK) { @@ -62,7 +67,5 @@ int main(int argc, char *argv[]) dbg_close(); - //close(fd); - return 0; } |