diff options
author | Jonas Gunz <himself@jonasgunz.de> | 2019-09-17 12:26:54 +0200 |
---|---|---|
committer | Jonas Gunz <himself@jonasgunz.de> | 2019-09-17 12:26:54 +0200 |
commit | 57cb704e6387fd1a84bb26e7242d49a1c268fb40 (patch) | |
tree | 140833a6cebb09cf5161e51f688fb88132c3ce1b /src/log.c | |
parent | 78771b749e406ba14e3014e66b4848ab1f897563 (diff) | |
download | bbs-57cb704e6387fd1a84bb26e7242d49a1c268fb40.tar.gz |
Added logging, fixed in unterminated buffers
Diffstat (limited to 'src/log.c')
-rw-r--r-- | src/log.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/log.c b/src/log.c new file mode 100644 index 0000000..36109c6 --- /dev/null +++ b/src/log.c @@ -0,0 +1,31 @@ +#include "log.h" + +const char* log_loglevel_str[5] = { + "---", + "ERROR", + "WARNING", + "NOTE", + "DEBUG" +}; + +int log_init_file(char* _file, unsigned int _verbosity) +{ + int fd = open(_file, O_WRONLY | O_APPEND | O_CREAT | O_DSYNC); + + if(fd < 0) { + LOGPRINTF(_LOG_ERROR, "Failed to open LogFile %s", _file); + } else { + dup2(fd, STDOUT_FILENO); + dup2(fd, STDERR_FILENO); + } + return log_init_stdout(_verbosity);; +} + +int log_init_stdout(unsigned int _verbosity) +{ + log_loglevel = _verbosity;// > _LOG_DEBUG ? _LOG_DEBUG : _verbosity; + LOGPRINTF(0, "=== RESTART ==="); + LOGPRINTF(0, "Verbosity: %i", _verbosity); + return 0; +} + |