blob: af974f85b594abc1951b4bfb77ad625f4887b529 [file] [log] [blame]
Jens Axboeac9b9102011-10-01 15:01:08 -04001#include <unistd.h>
2#include <fcntl.h>
3#include <string.h>
4#include <stdarg.h>
Jens Axboee46d8092011-10-03 09:11:02 +02005#include <syslog.h>
Jens Axboeac9b9102011-10-01 15:01:08 -04006
Jens Axboe3c39a372006-06-06 20:56:12 +02007#include "fio.h"
8
Jens Axboee46d8092011-10-03 09:11:02 +02009int log_valist(const char *str, va_list args)
10{
Jens Axboe734f38c2011-10-04 23:46:22 +020011 char buffer[1024];
12 size_t len;
Jens Axboee46d8092011-10-03 09:11:02 +020013
Jens Axboe734f38c2011-10-04 23:46:22 +020014 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 Axboee46d8092011-10-03 09:11:02 +020022}
23
Jens Axboe13755d92011-10-10 19:51:26 +020024int 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 Axboeac9b9102011-10-01 15:01:08 -040034int log_local(const char *format, ...)
Jens Axboe691c8fb2008-03-07 14:26:26 +010035{
Jens Axboeac9b9102011-10-01 15:01:08 -040036 char buffer[1024];
37 va_list args;
38 size_t len;
39
40 va_start(args, format);
Jens Axboe734f38c2011-10-04 23:46:22 +020041 len = vsnprintf(buffer, sizeof(buffer), format, args);
42 va_end(args);
Jens Axboeac9b9102011-10-01 15:01:08 -040043
Jens Axboe734f38c2011-10-04 23:46:22 +020044 if (log_syslog)
45 syslog(LOG_INFO, "%s", buffer);
46 else
47 len = fwrite(buffer, len, 1, f_out);
48
49 return len;
Jens Axboe691c8fb2008-03-07 14:26:26 +010050}
51
Jens Axboeac9b9102011-10-01 15:01:08 -040052int log_info(const char *format, ...)
Jens Axboe3c39a372006-06-06 20:56:12 +020053{
Jens Axboeac9b9102011-10-01 15:01:08 -040054 char buffer[1024];
55 va_list args;
56 size_t len;
Jens Axboef29b25a2007-07-23 08:56:43 +020057
Jens Axboeac9b9102011-10-01 15:01:08 -040058 va_start(args, format);
59 len = vsnprintf(buffer, sizeof(buffer), format, args);
60 va_end(args);
Jens Axboef29b25a2007-07-23 08:56:43 +020061
Jens Axboeac9b9102011-10-01 15:01:08 -040062 if (is_backend)
63 return fio_server_text_output(buffer, len);
Jens Axboe13755d92011-10-10 19:51:26 +020064 else if (log_syslog) {
65 syslog(LOG_INFO, "%s", buffer);
66 return len;
67 } else
Jens Axboeac9b9102011-10-01 15:01:08 -040068 return fwrite(buffer, len, 1, f_out);
Jens Axboef29b25a2007-07-23 08:56:43 +020069}
70
Jens Axboeac9b9102011-10-01 15:01:08 -040071int log_err(const char *format, ...)
Jens Axboef29b25a2007-07-23 08:56:43 +020072{
Jens Axboeac9b9102011-10-01 15:01:08 -040073 char buffer[1024];
74 va_list args;
75 size_t len;
Jens Axboef29b25a2007-07-23 08:56:43 +020076
Jens Axboeac9b9102011-10-01 15:01:08 -040077 va_start(args, format);
78 len = vsnprintf(buffer, sizeof(buffer), format, args);
79 va_end(args);
Jens Axboef29b25a2007-07-23 08:56:43 +020080
Jens Axboeac9b9102011-10-01 15:01:08 -040081 if (is_backend)
82 return fio_server_text_output(buffer, len);
Jens Axboe13755d92011-10-10 19:51:26 +020083 else if (log_syslog) {
84 syslog(LOG_INFO, "%s", buffer);
85 return len;
86 } else {
Jens Axboe1f39e552011-10-05 11:50:47 +020087 if (f_err != stderr) {
88 int fio_unused ret;
89
90 ret = fwrite(buffer, len, 1, stderr);
91 }
Jens Axboeac9b9102011-10-01 15:01:08 -040092
93 return fwrite(buffer, len, 1, f_err);
Jens Axboef29b25a2007-07-23 08:56:43 +020094 }
Jens Axboee3cedca2008-11-19 19:57:52 +010095}