Index: main/logger.c =================================================================== --- main/logger.c (revision 272147) +++ main/logger.c (working copy) @@ -83,6 +83,8 @@ static struct { unsigned int queue_log:1; + unsigned int queue_log_to_file:1; + unsigned int queue_adaptive_realtime:1; } logfiles = { 1 }; static char hostname[MAXHOSTNAMELEN]; @@ -340,8 +342,12 @@ ast_copy_string(dateformat, s, sizeof(dateformat)); else ast_copy_string(dateformat, "%b %e %T", sizeof(dateformat)); - if ((s = ast_variable_retrieve(cfg, "general", "queue_log"))) + if ((s = ast_variable_retrieve(cfg, "general", "queue_log"))) { logfiles.queue_log = ast_true(s); + } + if ((s = ast_variable_retrieve(cfg, "general", "queue_log_to_file"))) { + logfiles.queue_log_to_file = ast_true(s); + } if ((s = ast_variable_retrieve(cfg, "general", "queue_log_name"))) ast_copy_string(queue_log_name, s, sizeof(queue_log_name)); if ((s = ast_variable_retrieve(cfg, "general", "exec_after_rotate"))) @@ -438,27 +444,58 @@ vsnprintf(qlog_msg, sizeof(qlog_msg), fmt, ap); va_end(ap); snprintf(time_str, sizeof(time_str), "%ld", (long)time(NULL)); - ast_store_realtime("queue_log", "time", time_str, - "callid", callid, - "queuename", queuename, - "agent", agent, - "event", event, - "data", qlog_msg, - SENTINEL); - } else { - if (qlog) { - va_start(ap, fmt); - qlog_len = snprintf(qlog_msg, sizeof(qlog_msg), "%ld|%s|%s|%s|%s|", (long)time(NULL), callid, queuename, agent, event); - vsnprintf(qlog_msg + qlog_len, sizeof(qlog_msg) - qlog_len, fmt, ap); - va_end(ap); + if (logfiles.queue_adaptive_realtime) { + AST_DECLARE_APP_ARGS(args, + AST_APP_ARG(data)[5]; + ); + AST_NONSTANDARD_APP_ARGS(args, qlog_msg, '|'); + /* Ensure fields are large enough to receive data */ + ast_realtime_require_field("queue_log", "data1", RQ_CHAR, strlen(S_OR(args.data[0], "")), + "data2", RQ_CHAR, strlen(S_OR(args.data[1], "")), + "data3", RQ_CHAR, strlen(S_OR(args.data[2], "")), + "data4", RQ_CHAR, strlen(S_OR(args.data[3], "")), + "data5", RQ_CHAR, strlen(S_OR(args.data[4], "")), + SENTINEL); + + /* Store the log */ + ast_store_realtime("queue_log", "time", time_str, + "callid", callid, + "queuename", queuename, + "agent", agent, + "event", event, + "data1", S_OR(args.data[0], ""), + "data2", S_OR(args.data[1], ""), + "data3", S_OR(args.data[2], ""), + "data4", S_OR(args.data[3], ""), + "data5", S_OR(args.data[4], ""), + SENTINEL); + } else { + ast_store_realtime("queue_log", "time", time_str, + "callid", callid, + "queuename", queuename, + "agent", agent, + "event", event, + "data", qlog_msg, + SENTINEL); } - AST_RWLIST_RDLOCK(&logchannels); - if (qlog) { - fprintf(qlog, "%s\n", qlog_msg); - fflush(qlog); + + if (!logfiles.queue_log_to_file) { + return; } - AST_RWLIST_UNLOCK(&logchannels); } + + if (qlog) { + va_start(ap, fmt); + qlog_len = snprintf(qlog_msg, sizeof(qlog_msg), "%ld|%s|%s|%s|%s|", (long)time(NULL), callid, queuename, agent, event); + vsnprintf(qlog_msg + qlog_len, sizeof(qlog_msg) - qlog_len, fmt, ap); + va_end(ap); + } + AST_RWLIST_RDLOCK(&logchannels); + if (qlog) { + fprintf(qlog, "%s\n", qlog_msg); + fflush(qlog); + } + AST_RWLIST_UNLOCK(&logchannels); } static int rotate_file(const char *filename) @@ -946,14 +983,30 @@ ast_cli_register_multiple(cli_logger, ARRAY_LEN(cli_logger)); ast_mkdir(ast_config_AST_LOG_DIR, 0777); - + /* create log channels */ init_logger_chain(0 /* locked */); + ast_unload_realtime("queue_log"); if (logfiles.queue_log) { - snprintf(tmp, sizeof(tmp), "%s/%s", ast_config_AST_LOG_DIR, queue_log_name); - qlog = fopen(tmp, "a"); - ast_queue_log("NONE", "NONE", "NONE", "QUEUESTART", "%s", ""); + do { + if (ast_check_realtime("queue_log")) { + if (!ast_realtime_require_field("queue_log", "data1", RQ_CHAR, 20, + "data2", RQ_CHAR, 20, "data3", RQ_CHAR, 20, + "data4", RQ_CHAR, 20, "data5", RQ_CHAR, 20, SENTINEL)) { + logfiles.queue_adaptive_realtime = 1; + } else { + logfiles.queue_adaptive_realtime = 0; + } + + if (!logfiles.queue_log_to_file) { + break; + } + } + snprintf(tmp, sizeof(tmp), "%s/%s", ast_config_AST_LOG_DIR, queue_log_name); + qlog = fopen(tmp, "a"); + ast_queue_log("NONE", "NONE", "NONE", "QUEUESTART", "%s", ""); + } while (0); } return res; } Index: configs/logger.conf.sample =================================================================== --- configs/logger.conf.sample (revision 272147) +++ configs/logger.conf.sample (working copy) @@ -26,6 +26,10 @@ ; (defaults to yes). ;queue_log = no ; +; Determines whether the queue_log always goes to a file, even +; when a realtime backend is present (defaults to no). +;queue_log_to_file = yes +; ; Set the queue_log filename ; (defaults to queue_log) ;queue_log_name = queue_log