src/tests/libdlog_android_monotonic_neg \
src/tests/libdlog_base_pos \
src/tests/libdlog_base_neg \
+ src/tests/libdlog_prio_filter_pos \
src/tests/queued_entry_pos \
src/tests/queued_entry_neg \
src/tests/queued_entry_monotonic_pos \
src_tests_libdlog_base_neg_CFLAGS = $(check_CFLAGS) -pthread
src_tests_libdlog_base_neg_LDFLAGS = $(AM_LDFLAGS) -lpthread -Wl,--wrap=log_config_read,--wrap=snprintf
+src_tests_libdlog_prio_filter_pos_SOURCES = src/tests/libdlog_prio_filter_pos.c src/libdlog/log.c src/shared/logcommon.c src/shared/logconfig.c src/shared/parsers.c
+src_tests_libdlog_prio_filter_pos_CFLAGS = $(check_CFLAGS) -pthread
+src_tests_libdlog_prio_filter_pos_LDFLAGS = $(AM_LDFLAGS) -lpthread -Wl,--wrap=log_config_read
+
src_tests_log_file_SOURCES = src/tests/log_file.c src/shared/log_file.c
src_tests_log_file_CFLAGS = $(check_CFLAGS)
src_tests_log_file_LDFLAGS = $(AM_LDFLAGS) -Wl,--wrap=strdup,--wrap=free,--wrap=memcpy,--wrap=snprintf,--wrap=open,--wrap=open64,--wrap=fstat,--wrap=fstat64,--wrap=rename,--wrap=dlogutil_entry_get_timestamp,--wrap=log_print_log_line,--wrap=dlogutil_entry_get_tag,--wrap=isatty
* @endcode
*/
int __dlog_vprint(log_id_t log_id, int prio, const char *tag, const char *fmt, va_list ap);
+
+/**
+ * @brief Blocks low priority logs
+ * @details Allows filtering low priority logs globally, think a runtime "--verbose" mode,
+ * except you can choose which priorities to filter.
+ * Using this (as opposed to filtering later, when retrieving logs) is that it
+ * helps conserve system logging resources (buffer space etc.)
+ * @if MOBILE @since_tizen 6.0 @elseif WEARABLE @since_tizen 6.0 @endif
+ * @param[in] prio minimum priority level (of type #log_priority)
+ * @returns A DLOG_ERROR code
+ * @retval DLOG_ERROR_NONE Success
+ * @retval DLOG_ERROR_INVALID_PARAMETER Invalid priority parameter given
+ * @pre none
+ * @post none
+ * @see dlog_print
+ *
+ * @code
+#include<dlog.h>
+int main(void)
+{
+ dlog_print(DLOG_INFO, "TAG", "no filter so this log goes through");
+ dlog_set_minimum_priority(DLOG_WARN);
+ dlog_print(DLOG_INFO, "TAG", "WARN is a higher level than INFO so this log gets filtered");
+ dlog_print(DLOG_WARN, "TAG", "but this one still goes through");
+ dlog_print(DLOG_ERROR, "TAG", "as does this one");
+}
+ * @endcode
+ */
+int dlog_set_minimum_priority(int prio);
+
#ifdef __cplusplus
}
#endif /* __cplusplus */
static int debugmode;
static int fatal_assert;
static int limiter_apply_to_all_buffers;
+static _Atomic log_priority priority_filter_level = DLOG_VERBOSE;
static void __configure_limiter(struct log_config *config)
{
static int __write_to_log_critical_section(log_id_t log_id, int prio, const char *tag, const char *fmt, va_list ap, bool check_should_log)
{
+ if (check_should_log && prio < priority_filter_level)
+ return DLOG_ERROR_NONE;
+
if ((check_should_log || limiter_apply_to_all_buffers) && (dlog_check_limiter(log_id, prio, tag) < 0))
return DLOG_ERROR_NONE;
}
#endif
+int dlog_set_minimum_priority(int priority)
+{
+ if (priority < DLOG_DEFAULT || priority > DLOG_PRIO_MAX)
+ return DLOG_ERROR_INVALID_PARAMETER;
+
+ priority_filter_level = priority;
+ return DLOG_ERROR_NONE;
+}
+
/**
* @brief Print log
* @details Print a log line
--- /dev/null
+/* Copyright (c) 2020, Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License. */
+
+// C
+#include <assert.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <string.h>
+
+// DLog
+#include <dlog.h>
+#include <libdlog.h>
+#include <logconfig.h>
+
+int wtl(log_id_t buf_id, log_priority pri, const char *tag, const char *msg) { return 0xABCD; }
+void __dlog_init_pipe(const struct log_config *conf) { write_to_log = wtl; }
+
+int __wrap_log_config_read(struct log_config *config)
+{
+ config->begin = config->last = NULL;
+ log_config_set(config, "backend", "pipe");
+ log_config_set(config, "debugmode", "1");
+ return 0;
+}
+
+// lobotomize various mechanisms I don't want to deal with
+void __log_limiter_update(struct log_config *config) { }
+void __log_limiter_destroy(void) { }
+void __dynamic_config_destroy() { }
+int __log_limiter_pass_log(const char* tag, int prio) { return 1; }
+int __log_limiter_create(struct log_config *config) { return 1; }
+bool __dynamic_config_create(struct log_config *config) { return false; }
+void __dynamic_config_update() { }
+void __dlog_init_android(const struct log_config *conf) { }
+
+
+int main()
+{
+#define VALID_FILTER(x) assert(dlog_set_minimum_priority(x) == DLOG_ERROR_NONE)
+#define INVALID_FILTER(x) assert(dlog_set_minimum_priority(x) == DLOG_ERROR_INVALID_PARAMETER)
+#define ALLOW(x) assert(__dlog_print(LOG_ID_MAIN, x, "tag", "msg") == 0xABCD)
+#define BLOCK(x) assert(__dlog_print(LOG_ID_MAIN, x, "tag", "msg") == 0)
+
+ // Nothing should be filtered if there hasn't been a minimum set
+ for (int p = DLOG_VERBOSE; p < DLOG_PRIO_MAX; ++p)
+ ALLOW(p);
+
+ // The DEFAULT level should also not filter anything
+ VALID_FILTER(DLOG_DEFAULT);
+ for (int p = DLOG_VERBOSE; p < DLOG_PRIO_MAX; ++p)
+ ALLOW(p);
+
+ // The MAX filter should filter everything.
+ VALID_FILTER(DLOG_PRIO_MAX);
+ for (int p = DLOG_VERBOSE; p <= DLOG_SILENT; ++p)
+ BLOCK(p);
+
+ for (int l = DLOG_VERBOSE; l < DLOG_PRIO_MAX; ++l) {
+ VALID_FILTER(l);
+ for (int p = DLOG_VERBOSE; p < DLOG_PRIO_MAX; ++p)
+ if (p < l)
+ BLOCK(p);
+ else
+ ALLOW(p);
+ }
+
+ // Named priorities
+ INVALID_FILTER(DLOG_UNKNOWN);
+
+ // Adjacent to the allowed values
+ INVALID_FILTER(DLOG_DEFAULT - 1);
+ INVALID_FILTER(DLOG_PRIO_MAX + 1);
+
+ // Misc arbitrary values
+ INVALID_FILTER((log_priority) -1);
+ INVALID_FILTER((log_priority) 0);
+ INVALID_FILTER((log_priority) 57);
+
+#undef BLOCK
+#undef ALLOW
+#undef INVALID_FILTER
+#undef VALID_FILTER
+}