-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: David Bauer <[email protected]>
- Loading branch information
1 parent
f6c595a
commit d426f05
Showing
5 changed files
with
54 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,73 @@ | ||
#include <stdarg.h> | ||
#include <stdio.h> | ||
#include <syslog.h> | ||
#include "log.h" | ||
|
||
static enum log_level log_level = LOG_INFO; | ||
static enum log_level log_level = LL_INFO; | ||
static int use_syslog = 0; | ||
|
||
static void log_vprintf(enum log_level level, const char *fmt, va_list args) { | ||
const char *level_str; | ||
|
||
if (level < log_level) { | ||
if (level > log_level) { | ||
return; | ||
} | ||
|
||
switch (level) { | ||
case LOG_DEBUG: | ||
case LL_DEBUG: | ||
level_str = "DEBUG"; | ||
break; | ||
case LOG_INFO: | ||
case LL_INFO: | ||
level_str = "INFO"; | ||
break; | ||
case LOG_ERROR: | ||
case LL_WARNING: | ||
level_str = "WARNING"; | ||
break; | ||
case LL_ERROR: | ||
level_str = "ERROR"; | ||
break; | ||
case LL_FATAL: | ||
level_str = "FATAL"; | ||
break; | ||
default: | ||
level_str = "UNKNOWN"; | ||
break; | ||
} | ||
fprintf(stderr, "[%s] ", level_str); | ||
vfprintf(stderr, fmt, args); | ||
fprintf(stderr, "\n"); | ||
|
||
if (use_syslog) { | ||
vsyslog(LOG_INFO, fmt, args); | ||
} | ||
} | ||
|
||
void log_set_level(enum log_level level) { | ||
log_level = level; | ||
} | ||
|
||
void log_use_syslog(int use) { | ||
use_syslog = use; | ||
openlog("node-whisperer", 0, LOG_USER); | ||
} | ||
|
||
void log_error(const char *fmt, ...) { | ||
va_list args; | ||
va_start(args, fmt); | ||
log_vprintf(LOG_ERROR, fmt, args); | ||
log_vprintf(LL_ERROR, fmt, args); | ||
va_end(args); | ||
} | ||
|
||
void log_info(const char *fmt, ...) { | ||
va_list args; | ||
va_start(args, fmt); | ||
log_vprintf(LOG_INFO, fmt, args); | ||
log_vprintf(LL_INFO, fmt, args); | ||
va_end(args); | ||
} | ||
|
||
void log_debug(const char *fmt, ...) { | ||
va_list args; | ||
va_start(args, fmt); | ||
log_vprintf(LOG_DEBUG, fmt, args); | ||
log_vprintf(LL_DEBUG, fmt, args); | ||
va_end(args); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters