X-Git-Url: https://git.kernel.dk/?a=blobdiff_plain;f=log.c;h=362ab23c9813b9366c78ff55b4de8ffdd013a631;hb=0626037e3b4d9cb3cdc8c60dedf104f3d31b9484;hp=5d1d0b52d5f48ec09f705f3bea04dddb53d7160d;hpb=ac9b9101f1ef57965d6ffd51f143274a1eb665ef;p=fio.git diff --git a/log.c b/log.c index 5d1d0b52..362ab23c 100644 --- a/log.c +++ b/log.c @@ -2,9 +2,35 @@ #include #include #include +#include #include "fio.h" +int log_valist(const char *str, va_list args) +{ + char buffer[1024]; + size_t len; + + len = vsnprintf(buffer, sizeof(buffer), str, args); + + if (log_syslog) + syslog(LOG_INFO, "%s", buffer); + else + len = fwrite(buffer, len, 1, f_out); + + return len; +} + +int log_local_buf(const char *buf, size_t len) +{ + if (log_syslog) + syslog(LOG_INFO, "%s", buf); + else + len = fwrite(buf, len, 1, f_out); + + return len; +} + int log_local(const char *format, ...) { char buffer[1024]; @@ -15,7 +41,12 @@ int log_local(const char *format, ...) len = vsnprintf(buffer, sizeof(buffer), format, args); va_end(args); - return fwrite(buffer, len, 1, f_out); + if (log_syslog) + syslog(LOG_INFO, "%s", buffer); + else + len = fwrite(buffer, len, 1, f_out); + + return len; } int log_info(const char *format, ...) @@ -29,8 +60,11 @@ int log_info(const char *format, ...) va_end(args); if (is_backend) - return fio_server_text_output(buffer, len); - else + return fio_server_text_output(FIO_LOG_INFO, buffer, len); + else if (log_syslog) { + syslog(LOG_INFO, "%s", buffer); + return len; + } else return fwrite(buffer, len, 1, f_out); } @@ -45,10 +79,16 @@ int log_err(const char *format, ...) va_end(args); if (is_backend) - return fio_server_text_output(buffer, len); - else { - if (f_err != stderr) - fwrite(buffer, len, 1, stderr); + return fio_server_text_output(FIO_LOG_ERR, buffer, len); + else if (log_syslog) { + syslog(LOG_INFO, "%s", buffer); + return len; + } else { + if (f_err != stderr) { + int fio_unused ret; + + ret = fwrite(buffer, len, 1, stderr); + } return fwrite(buffer, len, 1, f_err); }