Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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

Signed-off-by: Angus Salkeld <asalkeld@redhat.com>
  • Loading branch information...
commit b52f2e37b3fa196e073a6103caa46adfcd0468b0 1 parent 460cc70
@asalkeld asalkeld authored
View
7 include/qb/qblog.h
@@ -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
4 lib/log.c
@@ -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
5 lib/log_file.c
@@ -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
1  lib/log_int.h
@@ -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;
Please sign in to comment.
Something went wrong with that request. Please try again.