el_set_file_sync¶
NAME¶
el_set_file_sync - configures condition on which logs should be force synced to disk.
SYNOPSIS¶
#include <embedlog.h>
int el_set_file_sync(long sync_every, enum el_level level);
int el_oset_file_sync(struct el *el, long sync_every, enum el_level level);
DESCRIPTION¶
This function sets both EL_FSYNC_EVERY and EL_FSYNC_LEVEL options.
EL_FSYNC_EVERY defines how often logs shall be synced to disk. Simply writing data to file descriptor is not enough, metadata also has to be synced or you are facing data loose on unexpected power loose. Yes, data will be on block device, but entry to it in file system will not be updated, thus system will think file did not change. To prevent that one must sync data and metadata periodically. Data will be synced every size of bytes written. It basically translates to 'how much data am I ready to loose?'. Set too high and you may loose a significant ammout of data on power lose. Set this too low and your performance goes out of the window. Setting this to 0 will result in all logs being flush ever time they are printed.
EL_FSYNC_LEVEL defines which log levels are always synced. If level of printed message is level or less (that is higher priority), it will be synced to disk every single time regardless of EL_FSYNC_EVERY option. Messages with level EL_FATAL (that is also default value for level sync) are synced always regardless of any options set. Messages printed with functions that don't take log level, will be treated as messages with EL_DBG level. If level is set to EL_DBG every message printed with any function will be immediately synced to drive (careful with that, this will impact performance a great deal if you print a lot of debug messages).
EXAMPLES¶
/* Sync logs once every 1024 bytes were written, or if log severity
* is higher than warning */
el_set_file_sync(1024, EL_WARN);
/* Sync all logs, with every print. In this case EL_WARN is useless */
el_set_file_sync(0, EL_WARN);
RETURN VALUE¶
0 on succes, or -1 and set errno on failure.