Jens Axboe | ac9b910 | 2011-10-01 15:01:08 -0400 | [diff] [blame] | 1 | #include <unistd.h> |
| 2 | #include <fcntl.h> |
| 3 | #include <string.h> |
| 4 | #include <stdarg.h> |
Jens Axboe | e46d809 | 2011-10-03 09:11:02 +0200 | [diff] [blame] | 5 | #include <syslog.h> |
Jens Axboe | ac9b910 | 2011-10-01 15:01:08 -0400 | [diff] [blame] | 6 | |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 7 | #include "fio.h" |
| 8 | |
Jens Axboe | e46d809 | 2011-10-03 09:11:02 +0200 | [diff] [blame] | 9 | int log_valist(const char *str, va_list args) |
| 10 | { |
Jens Axboe | 734f38c | 2011-10-04 23:46:22 +0200 | [diff] [blame] | 11 | char buffer[1024]; |
| 12 | size_t len; |
Jens Axboe | e46d809 | 2011-10-03 09:11:02 +0200 | [diff] [blame] | 13 | |
Jens Axboe | 734f38c | 2011-10-04 23:46:22 +0200 | [diff] [blame] | 14 | len = vsnprintf(buffer, sizeof(buffer), str, args); |
Ken Raeburn | 98ffb8f | 2013-01-30 22:31:09 +0100 | [diff] [blame^] | 15 | len = min(len, sizeof(buffer) - 1); |
Jens Axboe | 734f38c | 2011-10-04 23:46:22 +0200 | [diff] [blame] | 16 | |
| 17 | if (log_syslog) |
| 18 | syslog(LOG_INFO, "%s", buffer); |
| 19 | else |
| 20 | len = fwrite(buffer, len, 1, f_out); |
| 21 | |
| 22 | return len; |
Jens Axboe | e46d809 | 2011-10-03 09:11:02 +0200 | [diff] [blame] | 23 | } |
| 24 | |
Jens Axboe | 13755d9 | 2011-10-10 19:51:26 +0200 | [diff] [blame] | 25 | int log_local_buf(const char *buf, size_t len) |
| 26 | { |
| 27 | if (log_syslog) |
| 28 | syslog(LOG_INFO, "%s", buf); |
| 29 | else |
| 30 | len = fwrite(buf, len, 1, f_out); |
| 31 | |
| 32 | return len; |
| 33 | } |
| 34 | |
Jens Axboe | ac9b910 | 2011-10-01 15:01:08 -0400 | [diff] [blame] | 35 | int log_local(const char *format, ...) |
Jens Axboe | 691c8fb | 2008-03-07 14:26:26 +0100 | [diff] [blame] | 36 | { |
Jens Axboe | ac9b910 | 2011-10-01 15:01:08 -0400 | [diff] [blame] | 37 | char buffer[1024]; |
| 38 | va_list args; |
| 39 | size_t len; |
| 40 | |
| 41 | va_start(args, format); |
Jens Axboe | 734f38c | 2011-10-04 23:46:22 +0200 | [diff] [blame] | 42 | len = vsnprintf(buffer, sizeof(buffer), format, args); |
| 43 | va_end(args); |
Ken Raeburn | 98ffb8f | 2013-01-30 22:31:09 +0100 | [diff] [blame^] | 44 | len = min(len, sizeof(buffer) - 1); |
Jens Axboe | ac9b910 | 2011-10-01 15:01:08 -0400 | [diff] [blame] | 45 | |
Jens Axboe | 734f38c | 2011-10-04 23:46:22 +0200 | [diff] [blame] | 46 | if (log_syslog) |
| 47 | syslog(LOG_INFO, "%s", buffer); |
| 48 | else |
| 49 | len = fwrite(buffer, len, 1, f_out); |
| 50 | |
| 51 | return len; |
Jens Axboe | 691c8fb | 2008-03-07 14:26:26 +0100 | [diff] [blame] | 52 | } |
| 53 | |
Jens Axboe | ac9b910 | 2011-10-01 15:01:08 -0400 | [diff] [blame] | 54 | int log_info(const char *format, ...) |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 55 | { |
Jens Axboe | ac9b910 | 2011-10-01 15:01:08 -0400 | [diff] [blame] | 56 | char buffer[1024]; |
| 57 | va_list args; |
| 58 | size_t len; |
Jens Axboe | f29b25a | 2007-07-23 08:56:43 +0200 | [diff] [blame] | 59 | |
Jens Axboe | ac9b910 | 2011-10-01 15:01:08 -0400 | [diff] [blame] | 60 | va_start(args, format); |
| 61 | len = vsnprintf(buffer, sizeof(buffer), format, args); |
| 62 | va_end(args); |
Ken Raeburn | 98ffb8f | 2013-01-30 22:31:09 +0100 | [diff] [blame^] | 63 | len = min(len, sizeof(buffer) - 1); |
Jens Axboe | f29b25a | 2007-07-23 08:56:43 +0200 | [diff] [blame] | 64 | |
Jens Axboe | ac9b910 | 2011-10-01 15:01:08 -0400 | [diff] [blame] | 65 | if (is_backend) |
| 66 | return fio_server_text_output(buffer, len); |
Jens Axboe | 13755d9 | 2011-10-10 19:51:26 +0200 | [diff] [blame] | 67 | else if (log_syslog) { |
| 68 | syslog(LOG_INFO, "%s", buffer); |
| 69 | return len; |
| 70 | } else |
Jens Axboe | ac9b910 | 2011-10-01 15:01:08 -0400 | [diff] [blame] | 71 | return fwrite(buffer, len, 1, f_out); |
Jens Axboe | f29b25a | 2007-07-23 08:56:43 +0200 | [diff] [blame] | 72 | } |
| 73 | |
Jens Axboe | ac9b910 | 2011-10-01 15:01:08 -0400 | [diff] [blame] | 74 | int log_err(const char *format, ...) |
Jens Axboe | f29b25a | 2007-07-23 08:56:43 +0200 | [diff] [blame] | 75 | { |
Jens Axboe | ac9b910 | 2011-10-01 15:01:08 -0400 | [diff] [blame] | 76 | char buffer[1024]; |
| 77 | va_list args; |
| 78 | size_t len; |
Jens Axboe | f29b25a | 2007-07-23 08:56:43 +0200 | [diff] [blame] | 79 | |
Jens Axboe | ac9b910 | 2011-10-01 15:01:08 -0400 | [diff] [blame] | 80 | va_start(args, format); |
| 81 | len = vsnprintf(buffer, sizeof(buffer), format, args); |
| 82 | va_end(args); |
Ken Raeburn | 98ffb8f | 2013-01-30 22:31:09 +0100 | [diff] [blame^] | 83 | len = min(len, sizeof(buffer) - 1); |
Jens Axboe | f29b25a | 2007-07-23 08:56:43 +0200 | [diff] [blame] | 84 | |
Jens Axboe | ac9b910 | 2011-10-01 15:01:08 -0400 | [diff] [blame] | 85 | if (is_backend) |
| 86 | return fio_server_text_output(buffer, len); |
Jens Axboe | 13755d9 | 2011-10-10 19:51:26 +0200 | [diff] [blame] | 87 | else if (log_syslog) { |
| 88 | syslog(LOG_INFO, "%s", buffer); |
| 89 | return len; |
| 90 | } else { |
Jens Axboe | 1f39e55 | 2011-10-05 11:50:47 +0200 | [diff] [blame] | 91 | if (f_err != stderr) { |
| 92 | int fio_unused ret; |
| 93 | |
| 94 | ret = fwrite(buffer, len, 1, stderr); |
| 95 | } |
Jens Axboe | ac9b910 | 2011-10-01 15:01:08 -0400 | [diff] [blame] | 96 | |
| 97 | return fwrite(buffer, len, 1, f_err); |
Jens Axboe | f29b25a | 2007-07-23 08:56:43 +0200 | [diff] [blame] | 98 | } |
Jens Axboe | e3cedca | 2008-11-19 19:57:52 +0100 | [diff] [blame] | 99 | } |