int logfile_open(struct log_file *l_file);
int logfile_rotate_needed(struct log_file *l_file);
void logfile_do_rotate(struct log_file *file);
-int logfile_write_with_rotation(const struct dlogutil_entry *e, struct log_file *file, enum dlogutil_sorting_order sort_by);
+int logfile_write_with_rotation(const struct dlogutil_entry *e, struct log_file *file, dlogutil_sorting_order_e sort_by);
typedef int dlogutil_write_cb(const struct dlogutil_entry *e, void *userdata);
struct logfile_callback_data
{
struct log_file *file;
- enum dlogutil_sorting_order sort_by;
+ dlogutil_sorting_order_e sort_by;
};
int logfile_callback(const struct dlogutil_entry *e, void *userdata);
#define _LOGCONFIG_H_
#include <stdbool.h>
+#include <queued_entry.h>
#define MAX_CONF_KEY_LEN 32
#define MAX_CONF_VAL_LEN 256
void log_config_free(struct log_config *config);
void log_config_copy(struct log_config *dst, const struct log_config *src);
void log_config_foreach(const struct log_config *config, configIter iter, void *userdata);
-enum dlogutil_sorting_order get_order_from_config(const struct log_config *conf);
-enum dlogutil_sorting_order get_proper_sort_by(enum dlogutil_sorting_order sort_by, bool is_pipe, const struct log_config *conf, bool *sorting_needed);
+dlogutil_sorting_order_e get_order_from_config(const struct log_config *conf);
+dlogutil_sorting_order_e get_proper_sort_by(dlogutil_sorting_order_e sort_by, bool is_pipe, const struct log_config *conf, bool *sorting_needed);
#ifdef __cplusplus
}
log_priority filter_char_to_pri(char c);
char filter_pri_to_char(log_priority pri);
-enum dlogutil_sorting_order get_format_sorting(log_print_format format);
+dlogutil_sorting_order_e get_format_sorting(log_print_format format);
#ifdef __cplusplus
}
void additional_options_cleanup(struct additional_options *opt);
int create_initial_fdis(struct fd_info ***fdis, int enabled_buffers, bool is_pipe, const struct log_config *conf);
-int do_print(struct fd_info **data_fds, int fd_count, dlogutil_write_cb callback, void *userdata, bool sorting_needed, enum dlogutil_sorting_order sort_by, const struct log_config *conf, struct additional_options *opt);
+int do_print(struct fd_info **data_fds, int fd_count, dlogutil_write_cb callback, void *userdata, bool sorting_needed, dlogutil_sorting_order_e sort_by, const struct log_config *conf, struct additional_options *opt);
/**
* @brief sorting order
*/
-enum dlogutil_sorting_order {
+typedef enum dlogutil_sorting_order {
DLOGUTIL_SORT_SENT_MONO = 0,
DLOGUTIL_SORT_SENT_REAL,
DLOGUTIL_SORT_RECV_MONO,
DLOGUTIL_SORT_RECV_REAL,
DLOGUTIL_SORT_MAX,
DLOGUTIL_SORT_DEFAULT,
-};
+} dlogutil_sorting_order_e;
enum {
#include <stdbool.h>
#include <time.h>
#include <logconfig.h>
-
-struct dlogutil_entry;
-enum dlogutil_sorting_order;
+#include <queued_entry.h>
void add_recv_timestamp(struct dlogutil_entry *le);
void copy_recv_timestamp(struct dlogutil_entry *le);
-bool log_entry_is_earlier(const enum dlogutil_sorting_order sort_by, const struct dlogutil_entry *lhs, const struct dlogutil_entry *rhs);
-struct timespec dlogutil_entry_ts(const struct dlogutil_entry *le, enum dlogutil_sorting_order stamp_type);
-clockid_t get_proper_clock(enum dlogutil_sorting_order sort_by);
+bool log_entry_is_earlier(const dlogutil_sorting_order_e sort_by, const struct dlogutil_entry *lhs, const struct dlogutil_entry *rhs);
+struct timespec dlogutil_entry_ts(const struct dlogutil_entry *le, dlogutil_sorting_order_e stamp_type);
+clockid_t get_proper_clock(dlogutil_sorting_order_e sort_by);
#endif /* _QUEUED_ENTRY_TIMESTAMP_H */
size_t size;
long timeout;
size_t dump;
- enum dlogutil_sorting_order sort_by;
+ dlogutil_sorting_order_e sort_by;
bool old_logs_dumped;
struct timespec start; /* mark start to detect the moment when all "old" logs (existing before util has been invoked) have been dumped */
};
struct log_storage {
unsigned capacity; // maximum size of stored logs
- enum dlogutil_sorting_order sort_by; // stored logs sorting order
+ dlogutil_sorting_order_e sort_by; // stored logs sorting order
uint64_t counter_begin; // "pointer" to the first stored log in the log stream, see description above
uint64_t counter_end; // "pointer" to the end of the stored log stream
struct log_storage_entry *entries; // the log entries are stored here
uint64_t counter; // current position of the reader in the log stream
};
-log_storage *log_storage_create(unsigned capacity, enum dlogutil_sorting_order sort_by)
+log_storage *log_storage_create(unsigned capacity, dlogutil_sorting_order_e sort_by)
{
log_storage *storage = malloc(sizeof(*storage));
if (NULL != storage) {
log_storage_remove_the_earliest_log(storage);
}
-enum dlogutil_sorting_order log_storage_get_sorting_order(const log_storage *storage)
+dlogutil_sorting_order_e log_storage_get_sorting_order(const log_storage *storage)
{
assert(storage);
return storage->sort_by;
* @param[in] capacity Maximum capacity of the created instance.
* @return The created storage instance or NULL in case of lack of memory.
*/
-log_storage *log_storage_create(unsigned capacity, enum dlogutil_sorting_order sort_by);
+log_storage *log_storage_create(unsigned capacity, dlogutil_sorting_order_e sort_by);
/**
* @brief Frees the storage and all the resources associated with it.
* @brief Returns the sorting order of the storage, as specified on the storage creation.
* @return Log storage's sorting order.
*/
-enum dlogutil_sorting_order log_storage_get_sorting_order(const log_storage *storage);
+dlogutil_sorting_order_e log_storage_get_sorting_order(const log_storage *storage);
/**
* @brief This function adds a new entry to the storage.
if (ret < 0)
return ret;
- const enum dlogutil_sorting_order sort_by = get_order_from_config(&conf);
+ const dlogutil_sorting_order_e sort_by = get_order_from_config(&conf);
const char * const backend = log_config_get(&conf, "backend");
if (!backend) {
struct sock_data sock_ctl;
list_head readers;
log_id_t id;
- enum dlogutil_sorting_order sort_by;
+ dlogutil_sorting_order_e sort_by;
log_storage *log_storage;
};
int size;
struct socket_config_data write_socket;
struct socket_config_data ctl_socket;
- enum dlogutil_sorting_order sort_by;
+ dlogutil_sorting_order_e sort_by;
};
struct logger_config_data {
}
const bool is_pipe = !strcmp(backend, "pipe");
- enum dlogutil_sorting_order sort_by = get_format_sorting(l_file.format.format);
+ dlogutil_sorting_order_e sort_by = get_format_sorting(l_file.format.format);
bool sorting_needed;
- enum dlogutil_sorting_order proper_sort_by = get_proper_sort_by(sort_by, is_pipe, &conf, &sorting_needed);
+ dlogutil_sorting_order_e proper_sort_by = get_proper_sort_by(sort_by, is_pipe, &conf, &sorting_needed);
r = l_file.path ? logfile_open(&l_file) : 0;
if (r < 0) {
* @param[in] file The file to write to
* @returns 0 if log was successfully written, else 1
*/
-int logfile_write_with_rotation(const struct dlogutil_entry *e, struct log_file *file, enum dlogutil_sorting_order sort_by)
+int logfile_write_with_rotation(const struct dlogutil_entry *e, struct log_file *file, dlogutil_sorting_order_e sort_by)
{
if (file->colors_auto)
file->format.color = file->isatty;
}
}
-enum dlogutil_sorting_order get_order_from_config(const struct log_config *conf)
+dlogutil_sorting_order_e get_order_from_config(const struct log_config *conf)
{
- enum dlogutil_sorting_order ret = DLOGUTIL_SORT_RECV_MONO;
+ dlogutil_sorting_order_e ret = DLOGUTIL_SORT_RECV_MONO;
const char *const sort_str = log_config_get(conf, "sort_by");
if (sort_str) {
return ret;
}
-enum dlogutil_sorting_order get_proper_sort_by(enum dlogutil_sorting_order sort_by, bool is_pipe, const struct log_config *conf, bool *sorting_needed)
+dlogutil_sorting_order_e get_proper_sort_by(dlogutil_sorting_order_e sort_by, bool is_pipe, const struct log_config *conf, bool *sorting_needed)
{
- enum dlogutil_sorting_order source_sorting = get_order_from_config(conf);
+ dlogutil_sorting_order_e source_sorting = get_order_from_config(conf);
*sorting_needed = false;
return entry->msg + entry->tag_len + 1 /* NULL delimiter */;
}
-enum dlogutil_sorting_order get_format_sorting(log_print_format format)
+dlogutil_sorting_order_e get_format_sorting(log_print_format format)
{
switch (format) {
case FORMAT_TAG:
log_filter_free(opt->filter_object);
}
-struct fd_info *find_earliest_log(struct fd_info **data_fds, int fd_count, enum dlogutil_sorting_order sort_by)
+struct fd_info *find_earliest_log(struct fd_info **data_fds, int fd_count, dlogutil_sorting_order_e sort_by)
{
assert(data_fds);
* @param[in] l_file File output metadata
* @return int 0 if successful, a negative value on error, callback's return value if it isn't 0
*/
-int do_print(struct fd_info **data_fds, int fd_count, dlogutil_write_cb callback, void *userdata, bool sorting_needed, enum dlogutil_sorting_order sort_by, const struct log_config *conf, struct additional_options *opt)
+int do_print(struct fd_info **data_fds, int fd_count, dlogutil_write_cb callback, void *userdata, bool sorting_needed, dlogutil_sorting_order_e sort_by, const struct log_config *conf, struct additional_options *opt)
{
assert(data_fds);
assert(conf);
le->nsec_recv_real = le->nsec_sent_real;
}
-bool log_entry_is_earlier(const enum dlogutil_sorting_order sort_by, const struct dlogutil_entry *lhs, const struct dlogutil_entry *rhs)
+bool log_entry_is_earlier(const dlogutil_sorting_order_e sort_by, const struct dlogutil_entry *lhs, const struct dlogutil_entry *rhs)
{
assert(lhs);
assert(rhs);
return l_sec < r_sec || (l_sec == r_sec && l_nsec < r_nsec);
}
-struct timespec dlogutil_entry_ts(const struct dlogutil_entry *le, enum dlogutil_sorting_order stamp_type)
+struct timespec dlogutil_entry_ts(const struct dlogutil_entry *le, dlogutil_sorting_order_e stamp_type)
{
assert(le);
return ret;
}
-clockid_t get_proper_clock(enum dlogutil_sorting_order sort_by)
+clockid_t get_proper_clock(dlogutil_sorting_order_e sort_by)
{
switch (sort_by) {
case DLOGUTIL_SORT_SENT_MONO:
* @param[out] callback_ret Return value of the callback if it has been called
* @return bool whether the log was old enough
*/
-bool process_log(const struct dlogutil_entry *e, struct timespec reference_ts, enum dlogutil_sorting_order stamp_type, dlogutil_write_cb callback, void *userdata, long timeout, int *callback_ret)
+bool process_log(const struct dlogutil_entry *e, struct timespec reference_ts, dlogutil_sorting_order_e stamp_type, dlogutil_write_cb callback, void *userdata, long timeout, int *callback_ret)
{
assert(e);
assert(callback_ret);
return fail_extract ? NULL : (struct dlogutil_entry *) 0xBADFEEL;
}
-struct timespec __wrap_dlogutil_entry_ts(const struct dlogutil_entry *le, enum dlogutil_sorting_order stamp_type)
+struct timespec __wrap_dlogutil_entry_ts(const struct dlogutil_entry *le, dlogutil_sorting_order_e stamp_type)
{
assert(le == (struct dlogutil_entry *)0xBADFEEL);
return (struct timespec) {
return -1;
}
-struct timespec __wrap_dlogutil_entry_ts(const struct dlogutil_entry *le, enum dlogutil_sorting_order stamp_type)
+struct timespec __wrap_dlogutil_entry_ts(const struct dlogutil_entry *le, dlogutil_sorting_order_e stamp_type)
{
assert(stamp_type == DLOGUTIL_SORT_SENT_MONO);
assert(le == (struct dlogutil_entry *) 0xBA5EBALL);
{
static const struct {
log_print_format format;
- enum dlogutil_sorting_order sorting;
+ dlogutil_sorting_order_e sorting;
} expected_sorting[] = {
{FORMAT_TAG , DLOGUTIL_SORT_DEFAULT },
{FORMAT_PROCESS , DLOGUTIL_SORT_DEFAULT },
#include <sort_vector.h>
#include <fd_info.h>
-bool process_log(const struct dlogutil_entry *e, struct timespec reference_ts, enum dlogutil_sorting_order stamp_type, dlogutil_write_cb callback, void *userdata, long timeout, int *callback_ret);
-struct fd_info *find_earliest_log(struct fd_info **data_fds, int fd_count, enum dlogutil_sorting_order sort_by);
+bool process_log(const struct dlogutil_entry *e, struct timespec reference_ts, dlogutil_sorting_order_e stamp_type, dlogutil_write_cb callback, void *userdata, long timeout, int *callback_ret);
+struct fd_info *find_earliest_log(struct fd_info **data_fds, int fd_count, dlogutil_sorting_order_e sort_by);
int put_logs_into_vector(struct fd_info **data_fds, int fd_count, int nfds, struct sort_vector *logs, dlogutil_write_cb callback, void *userdata, dlogutil_filter_options_s *filter);
int validate_buffers(int *enabled_buffers);
struct log_config conf = {NULL, NULL};
const struct {
const char *const str;
- enum dlogutil_sorting_order order;
+ dlogutil_sorting_order_e order;
} ordering[] = {
{ "sent_real", DLOGUTIL_SORT_SENT_REAL },
{ "sent_mono", DLOGUTIL_SORT_SENT_MONO },
return callback_ret;
}
-bool __wrap_log_entry_is_earlier(const enum dlogutil_sorting_order sort_by, const struct dlogutil_entry *lhs, const struct dlogutil_entry *rhs)
+bool __wrap_log_entry_is_earlier(const dlogutil_sorting_order_e sort_by, const struct dlogutil_entry *lhs, const struct dlogutil_entry *rhs)
{
return lhs < rhs;
}