LOG: make it possible to fsync() on each file log.

Signed-off-by: Angus Salkeld <asalkeld@redhat.com>
This commit is contained in:
Angus Salkeld 2012-06-05 12:07:35 +10:00
parent 460cc70a8b
commit b52f2e37b3
4 changed files with 17 additions and 0 deletions

View File

@ -98,6 +98,12 @@ extern "C" {
* LOG_INFO - LOG_DEBUG);
* @endcode
*
* To ensure all logs to file targets are fsync'ed (default QB_FALSE)
* @code
* qb_log_ctl(mytarget, QB_LOG_CONF_FILE_SYNC, QB_TRUE);
* @endcode
*
*
* @par Filtering messages.
* To have more power over what log messages go to which target you can apply
* filters to the targets. What happens is the desired callsites have the
@ -393,6 +399,7 @@ enum qb_log_conf {
QB_LOG_CONF_THREADED,
QB_LOG_CONF_PRIORITY_BUMP,
QB_LOG_CONF_STATE_GET,
QB_LOG_CONF_FILE_SYNC,
};
enum qb_log_filter_type {

View File

@ -730,6 +730,7 @@ qb_log_init(const char *name, int32_t facility, uint8_t priority)
for (i = 0; i < QB_LOG_TARGET_MAX; i++) {
conf[i].pos = i;
conf[i].debug = QB_FALSE;
conf[i].file_sync = QB_FALSE;
conf[i].state = QB_LOG_STATE_UNUSED;
(void)strlcpy(conf[i].name, name, PATH_MAX);
conf[i].facility = facility;
@ -967,6 +968,9 @@ qb_log_ctl(int32_t t, enum qb_log_conf c, int32_t arg)
need_reload = QB_TRUE;
}
break;
case QB_LOG_CONF_FILE_SYNC:
conf[t].file_sync = arg;
break;
case QB_LOG_CONF_PRIORITY_BUMP:
conf[t].priority_bump = arg;
break;

View File

@ -26,6 +26,7 @@ _file_logger(int32_t t,
struct qb_log_callsite *cs, time_t timestamp, const char *msg)
{
char output_buffer[QB_LOG_MAX_LEN];
struct qb_log_target *target = qb_log_target_get(t);
FILE *f = qb_log_target_user_data_get(t);
if (f == NULL) {
@ -36,7 +37,11 @@ _file_logger(int32_t t,
qb_log_target_format(t, cs, timestamp, msg, output_buffer);
fprintf(f, "%s\n", output_buffer);
fflush(f);
if (target->file_sync) {
fsync(fileno(f));
}
}
static void

View File

@ -35,6 +35,7 @@ struct qb_log_target {
struct qb_list_head filter_head;
int32_t facility;
int32_t priority_bump;
int32_t file_sync;
int32_t debug;
size_t size;
char *format;