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