dlogutil_SOURCES = \
src/logutil/logutil.c \
src/shared/logcommon.c \
+ src/shared/logconfig.c \
src/shared/logprint.c \
src/shared/log_file.c \
+ src/shared/parsers.c \
src/shared/ptrs_list.c \
src/shared/util_parser.c
src_tests_test_fastlz_neg_CFLAGS = $(check_CFLAGS)
src_tests_test_fastlz_neg_LDFLAGS = $(AM_LDFLAGS)
-src_tests_fuzz_logprint_SOURCES = src/tests/fuzz_logprint.c src/shared/ptrs_list.c src/shared/logprint.c src/shared/logcommon.c src/shared/queued_entry.c src/shared/parsers.c src/shared/translate_syslog.c src/shared/queued_entry_timestamp.c
+src_tests_fuzz_logprint_SOURCES = src/tests/fuzz_logprint.c src/shared/ptrs_list.c src/shared/logconfig.c src/shared/logprint.c src/shared/logcommon.c src/shared/queued_entry.c src/shared/parsers.c src/shared/translate_syslog.c src/shared/queued_entry_timestamp.c
src_tests_fuzz_logprint_CFLAGS = $(check_CFLAGS)
src_tests_fuzz_logprint_LDFLAGS = $(AM_LDFLAGS)
src_tests_config_CFLAGS = $(check_CFLAGS)
src_tests_config_LDFLAGS = $(AM_LDFLAGS) -Wl,--wrap=openat64,--wrap=openat,--wrap=scandirat,--wrap=scandirat64,--wrap=fdopen,--wrap=fdopen64,--wrap=open,--wrap=open64,--wrap=calloc
-src_tests_logprint_SOURCES = src/tests/logprint.c src/shared/ptrs_list.c src/shared/logprint.c src/shared/logcommon.c src/shared/queued_entry.c src/shared/parsers.c src/shared/translate_syslog.c src/shared/queued_entry_timestamp.c
+src_tests_logprint_SOURCES = src/tests/logprint.c src/shared/ptrs_list.c src/shared/logconfig.c src/shared/logprint.c src/shared/logcommon.c src/shared/queued_entry.c src/shared/parsers.c src/shared/translate_syslog.c src/shared/queued_entry_timestamp.c
src_tests_logprint_CFLAGS = $(check_CFLAGS)
src_tests_logprint_LDFLAGS = $(AM_LDFLAGS) -Wl,--wrap=write,--wrap=malloc,--wrap=calloc,--wrap=localtime_r,--wrap=strdup,--wrap=strndup,--wrap=list_add
src_tests_pid_limiter_CFLAGS = $(check_CFLAGS) -Wl,--wrap=getpid,--wrap=time
src_tests_pid_limiter_LDFLAGS = $(AM_LDFLAGS)
-src_tests_filters_SOURCES = src/tests/filters.c src/shared/ptrs_list.c src/shared/logcommon.c src/shared/logprint.c src/shared/queued_entry_timestamp.c
+src_tests_filters_SOURCES = src/tests/filters.c src/shared/ptrs_list.c src/shared/logcommon.c src/shared/logconfig.c src/shared/logprint.c src/shared/queued_entry_timestamp.c src/shared/parsers.c
src_tests_filters_CFLAGS = $(check_CFLAGS)
src_tests_filters_LDFLAGS = $(AM_LDFLAGS)
# agrees with what the source provides.
#util_sorting_buffer_size=131072
+# Default output format. This applies both to explicit dlogutil calls and
+# persistent logging (i.e. writing to a file defined in daemon config).
+# By default this is brief, but this will work even if the option is not provided explicitly.
+#util_default_format=brief
+
# Deduplication blocks logs within the certain period of time (interval_millisec) starting from last_millisec.
# Block logs when neighbouring logs have the same content. It is quite simple deduplication,
struct log_write_buffer *buf);
dlogutil_sorting_order_e get_format_sorting(log_print_format format);
+log_print_format get_default_format_from_config(const struct log_config *conf);
#ifdef __cplusplus
}
* @remarks The output struct might contain parts of argv. Also, argv won't be modified.
* @param[in] argc Size of the argv array
* @param[out] argv Array of string arguments
+ * @param[in] log_print_format Format returned in case of none provided
* @return A result struct
*/
-struct parse_result parse_options(int argc, char **argv);
+struct parse_result parse_options(int argc, char **argv, log_print_format default_format);
/**
* @brief Free contents of the #parse_result struct
* @remarks The struct itself won't be freed (as usually it's passed on the stack).
return 0;
}
-static int get_dlogutil_params_from_argc_argv(int argc, char **argv, struct dlogutil_line_params *params)
+static int get_dlogutil_params_from_argc_argv(int argc, char **argv, log_print_format default_format, struct dlogutil_line_params *params)
{
assert(argc >= 0);
assert(argv);
assert(params);
- __attribute__((cleanup(parse_result_cleanup))) struct parse_result pr = parse_options(argc, argv);
+ __attribute__((cleanup(parse_result_cleanup))) struct parse_result pr = parse_options(argc, argv, default_format);
if (pr.status == PARSE_OOM)
return -ENOMEM;
return 0;
}
-int get_dlogutil_line_params(const char *cmdl, struct dlogutil_line_params *params)
+int get_dlogutil_line_params(const char *cmdl, log_print_format default_format, struct dlogutil_line_params *params)
{
assert(params);
assert(cmdl);
if (ret < 0)
return ret;
- return get_dlogutil_params_from_argc_argv(argc, argv, params);
+ return get_dlogutil_params_from_argc_argv(argc, argv, default_format, params);
}
};
bool initialize_dlogutil_line_params(struct dlogutil_line_params *params, struct buf_params buf);
-int get_dlogutil_line_params(const char *cmdl, struct dlogutil_line_params *params);
+int get_dlogutil_line_params(const char *cmdl, log_print_format default_format, struct dlogutil_line_params *params);
void free_dlogutil_line_params(struct dlogutil_line_params *params);
goto cleanup;
}
- retval = get_dlogutil_line_params(msg->data, ¶ms);
+ /* Note that in this case, the format doesn't matter.
+ * Therefore, we just pass OFF as default. */
+ retval = get_dlogutil_line_params(msg->data, FORMAT_OFF, ¶ms);
if (retval < 0) {
// retval = -ENOMEM; // see above
goto cleanup;
goto cleanup;
}
- retval = get_dlogutil_line_params(msg->data, ¶ms);
+ /* Note that in this case, the format doesn't matter.
+ * Therefore, we just pass OFF as default. */
+ retval = get_dlogutil_line_params(msg->data, FORMAT_OFF, ¶ms);
if (retval < 0) {
// retval = -ENOMEM; // see above
goto cleanup;
data->logfile_configs = NULL;
log_config_foreach(&conf, save_logfile_config, data);
+ data->default_format = get_default_format_from_config(&conf);
+
end:
log_config_free(&conf);
return ret;
free(data->first_time_file_path);
}
+struct parse_logfile_config_data {
+ struct logger *server;
+ struct logger_config_data *data;
+};
+
/**
* @brief Parse logfile line
* @detail Parses a logfile config line
assert(value);
assert(userdata);
- struct logger *server = (struct logger *) userdata;
+ struct logger *server = ((struct parse_logfile_config_data *) userdata)->server;
+ struct logger_config_data *data = ((struct parse_logfile_config_data *) userdata)->data;
char *configline = (char *) value;
__attribute__((cleanup(free_dlogutil_line_params))) struct dlogutil_line_params params;
if (!initialize_dlogutil_line_params(¶ms, server->buf_params))
return;
- get_dlogutil_line_params(configline, ¶ms);
+ get_dlogutil_line_params(configline, data->default_format, ¶ms);
int r;
if (g_backend.use_logger_by_default && is_core_buffer(params.buf_id)) {
return r;
//create files after resetting self privileges
- list_foreach(data->logfile_configs, server, parse_logfile_config);
+ list_foreach(data->logfile_configs, &(struct parse_logfile_config_data) {
+ .server = server,
+ .data = data,
+ }, parse_logfile_config);
return 0;
}
int qos_threshold;
int qos_threshold_reapply;
char *first_time_file_path;
+ log_print_format default_format;
};
void remove_reader_fd_entities(struct logger *server, struct reader_common *reader);
#include <fcntl.h>
#include <sys/epoll.h>
+#include <logconfig.h>
#include <log_file.h>
#include <util_parser.h>
logfile_init(&l_file);
logfile_set_fd(&l_file, fileno(stdout), 0);
- __attribute__((cleanup(parse_result_cleanup))) struct parse_result pr = parse_options(argc, argv);
+ __attribute__((cleanup(log_config_free))) struct log_config conf = {};
+ int r = log_config_read(&conf);
+ if (r < 0) {
+ errno = -r;
+ ERR("Error while reading config: %m");
+ }
+
+ __attribute__((cleanup(parse_result_cleanup))) struct parse_result pr = parse_options(argc, argv, get_default_format_from_config(&conf));
switch (pr.status) {
case PARSE_OK:
break;
int enabled_buffers = pr.enabled_buffers != 0 ? pr.enabled_buffers : default_buffers;
- int r;
switch (pr.action) {
case ACTION_PRINT: {
r = do_print(pr.mode, pr.dump_size, enabled_buffers, pr.sort_by, config, &l_file, pr.compression);
#include <ctype.h>
#include <tizen.h>
+#include <logconfig.h>
#include <logprint.h>
#include <logcommon.h>
return FORMAT_OFF;
}
+/* This goes here and not into logconfig.c, as otherwise everything that builds with logconfig.c
+ * needs to build needlessly with logprint.c. */
+log_print_format get_default_format_from_config(const struct log_config *conf)
+{
+ assert(conf);
+
+ const char *const name = log_config_get(conf, "util_default_format");
+ if (name == NULL)
+ return FORMAT_BRIEF;
+
+ const log_print_format returned = log_format_from_string(name);
+ if (returned == FORMAT_OFF)
+ return FORMAT_BRIEF;
+
+ return returned;
+}
+
int priority_from_filter_expression(const char *filterExpression, bool *exact, log_priority *pri)
{
assert(exact);
}
}
-struct parse_result parse_options(int argc, char **argv)
+struct parse_result parse_options(int argc, char **argv, log_print_format default_format)
{
bool colors_auto = true;
bool colors_force = false;
- log_print_format format = FORMAT_BRIEF;
+ log_print_format format = default_format;
size_t rotate_size_kbytes = DEFAULT_ROTATE_SIZE_KB;
size_t max_rotated = DEFAULT_ROTATE_NUM_FILES;
const char *file_path = NULL;
LOG_DETAILS="testing if libdlogutil errors out correctly if used improperly"
test_libdlogutil negative $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
-cmd_prefix="dlogutil -t 1 -u 0 -v"
+cmd_prefix_no_v="dlogutil -t 1 -u 0"
+cmd_prefix="$cmd_prefix_no_v -v"
format="process"
regex_prio="[VDIWEFS]{1}"
line=$($cmd_prefix $format)
[ "$(echo "$line" | sed -re "$REGEX")" = "1" ] && ok || fail
+SOURCE="$DLOG_CONFIG_PATH"
+DLOG_CONFIG_PATH="$TESTDIR/defaultprintformat.conf"
+cp "$SOURCE" "$DLOG_CONFIG_PATH"
+
+# TODO: It would be good to also test the daemon side of things.
+LOG_DETAILS="testing default log format selection (none -> brief)"
+REGEX="s/^$regex_prio\/[[:print:]]{8,}\([0-9[:space:]]{5,}\):\s{1}[[:print:]]*$/1/g"
+line=$($cmd_prefix_no_v)
+[ "$(echo "$line" | sed -re "$REGEX")" = "1" ] && ok || fail
+
+echo "util_default_format=rwtime" >> $DLOG_CONFIG_PATH
+LOG_DETAILS="testing default log format selection (rwtime)"
+REGEX="s/^$regex_time\s{1}\[[0-9[:space:]]{3,}.[0-9[:space:]]{3,}\]\s{1}$regex_prio\/[[:print:]]{8,}\($regex_pidtid\):\s{1}[[:print:]]*$/1/g"
+line=$($cmd_prefix_no_v)
+[ "$(echo "$line" | sed -re "$REGEX")" = "1" ] && ok || fail
+
+DLOG_CONFIG_PATH="$SOURCE"
+
format="raw"
LOG_DETAILS="testing if \"$format\" print format works"
dlogutil -c