Initial attempt of log rotation based on file sizes

This commit is contained in:
Nils O. Selåsdal
2014-04-23 02:04:08 +02:00
parent bc27ed462b
commit 0e35ecbc29
3 changed files with 149 additions and 14 deletions
+38
View File
@@ -132,6 +132,33 @@ struct UCLogModules {
struct UCLogDestination;
enum UC_LOG_ROTATE_POLICY {
/** Don't rotate. Default setting*/
UC_LOG_ROTATE_NONE,
/** Create a new log file every 'size' bytes */
UC_LOG_ROTATE_SIZE
};
/** Log rotate settings that can be set on a UC_LDEST_FILE destination
* The default is to not rotate log files.
* The current log file wil always be the specified file name,
* For UC_LOG_ROTATE_SIZE the current file will be renamed when it exceeds
* the specified max_size with a .number suffix (e.g .0 , .1 , .2 and so on),
* up to num_files are kept and a new log file is created.
*/
struct UCLogRotateSettings {
/** Policy */
enum UC_LOG_ROTATE_POLICY policy;
/** For UC_LOG_ROTATE_SIZE policy */
struct {
/** Max size of an individual log file */
size_t max_size;
/** Max number of log files to keep.
* Is forced to be at least 1*/
unsigned int num_files;
} size_settings;
};
/* Returns a string representation of the log level.
*
@@ -204,6 +231,17 @@ void uc_log_destination_set_loglevel(struct UCLogDestination *dest, enum UC_LOG_
* @param log_location 1=log the locaton, 0=don't log the location
*/
void uc_log_destination_set_log_location(struct UCLogDestination *dest, int log_location);
/** Sets the log rotation settings.
* Does nothing if the destination is not a UC_LDEST_FILE, or the policy is invalid.
* The default is to not do log rotation
*
* @param dest log destination to change
* @param settings new policy to set
*/
void uc_log_destination_set_rotate_policy(struct UCLogDestination *dest,
const struct UCLogRotateSettings *settings);
/** Remove and free a destination.
* This frees the memory allocated to the destination. For
* UC_LDEST_FILE the log file is closed.