From: Michal Bloch Date: Mon, 20 Feb 2023 15:29:19 +0000 (+0100) Subject: Add the 'dotnet' and 'native' extra libdlog sinks X-Git-Tag: accepted/tizen/unified/20230222.161514~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F96%2F288296%2F4;p=platform%2Fcore%2Fsystem%2Fdlog.git Add the 'dotnet' and 'native' extra libdlog sinks Including dlog_[v]print_{dotnet,native} interfaces. Change-Id: Ie1692f8302dd42fa9d7f399b158c3190137406a9 Signed-off-by: Michal Bloch --- diff --git a/configs/99-dlog-logger.disable-platform-logging-for-testsuite.conf b/configs/99-dlog-logger.disable-platform-logging-for-testsuite.conf index 32a9150..1e2c681 100644 --- a/configs/99-dlog-logger.disable-platform-logging-for-testsuite.conf +++ b/configs/99-dlog-logger.disable-platform-logging-for-testsuite.conf @@ -6,6 +6,8 @@ enable_main=0 enable_system=0 enable_radio=0 enable_apps=0 +enable_dotnet_api=0 +enable_native_api=0 # remove the backup redirection from apps to main that exists in the regular config diff --git a/configs/dlog.conf b/configs/dlog.conf index 296995a..39a3c59 100644 --- a/configs/dlog.conf +++ b/configs/dlog.conf @@ -15,9 +15,14 @@ enable_main=1 enable_radio=1 enable_system=1 enable_apps=1 + # enable_kmsg = 1 # DOESN'T WORK! KMSG is not a libdlog-populated buffer. See below for `handle_kmsg` instead. enable_critical=1 +# these two are not full buffers, they are just log sinks that redirect to the 'apps' buffer. +enable_dotnet_api=1 +enable_native_api=1 + # Debugmode - whether write platform debug log or not # If disabled, logs at priority levels DEBUG and below - this means also VERBOSE - are completely dropped debugmode=1 diff --git a/include/dlog.h b/include/dlog.h index eee1c82..1cdf905 100644 --- a/include/dlog.h +++ b/include/dlog.h @@ -183,6 +183,86 @@ int dlog_vprint(log_priority prio, const char *tag, const char *fmt, va_list ap) /** + * @brief Sends log with priority and tag + * @details The same as 'dlog_print' except controlled by 'enable_dotnet_api' + * instead of 'enable_apps' + * @since_tizen 7.5 + * @param[in] prio priority level of type #log_priority + * @param[in] tag tag - a null-terminated string + * @param[in] fmt format string - same as printf + * @return On success, the function returns the number of bytes written. + * On error, a negative errno-style error code + * @retval #DLOG_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #DLOG_ERROR_NOT_PERMITTED Operation not permitted + * @pre none + * @post none + * @see dlog_vprint_dotnet + * @see dlog_print + */ +int dlog_print_dotnet(log_priority prio, const char *tag, const char *fmt, ...) __attribute__((format(printf, 3, 4))); + +/** + * @brief Sends log with priority and tag + * @details The same as 'dlog_print' except controlled by 'enable_native_api' + * instead of 'enable_apps' + * @since_tizen 7.5 + * @param[in] prio priority level of type #log_priority + * @param[in] tag tag - a null-terminated string + * @param[in] fmt format string - same as printf + * @return On success, the function returns the number of bytes written. + * On error, a negative errno-style error code + * @retval #DLOG_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #DLOG_ERROR_NOT_PERMITTED Operation not permitted + * @pre none + * @post none + * @see dlog_vprint_native + * @see dlog_print + */ +int dlog_print_native(log_priority prio, const char *tag, const char *fmt, ...) __attribute__((format(printf, 3, 4))); + + +/** + * @brief Sends log with priority, tag, and va_list. + * @details The same as 'dlog_vprint' except controlled by 'enable_dotnet_api' + * instead of 'enable_apps' + * @since_tizen 7.5 + * @param[in] prio priority level of type #log_priority + * @param[in] tag tag - a null-terminated string + * @param[in] fmt format string - same as printf + * @param[in] ap va_list + * @return On success, the function returns the number of bytes written. + * On error, a negative errno-style error code + * @retval #DLOG_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #DLOG_ERROR_NOT_PERMITTED Operation not permitted + * @pre none + * @post none + * @see dlog_print_dotnet + * @see dlog_vprint + */ +int dlog_vprint_dotnet(log_priority prio, const char *tag, const char *fmt, va_list ap); + +/** + * @brief Sends log with priority, tag, and va_list. + * @details The same as 'dlog_vprint' except controlled by 'enable_native_api' + * instead of 'enable_apps' + * @since_tizen 7.5 + * @param[in] prio priority level of type #log_priority + * @param[in] tag tag - a null-terminated string + * @param[in] fmt format string - same as printf + * @param[in] ap va_list + * @return On success, the function returns the number of bytes written. + * On error, a negative errno-style error code + * @retval #DLOG_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #DLOG_ERROR_NOT_PERMITTED Operation not permitted + * @pre none + * @post none + * @see dlog_print_native + * @see dlog_vprint + */ +int dlog_vprint_native(log_priority prio, const char *tag, const char *fmt, va_list ap); + + +/** * @} */ diff --git a/include/extra_sinks.h b/include/extra_sinks.h index 3661f3b..2ffb741 100644 --- a/include/extra_sinks.h +++ b/include/extra_sinks.h @@ -5,7 +5,14 @@ * other LOG_ID_XYZ constants and have to be handled separately. The upside is * that the requirement to hardcode them to redirect to a core buffer means that * we can keep the existence of these buffers to a handful of files as logs will - * become basically undistinguishable to other programs once they get sent. */ + * become basically undistinguishable to other programs once they get sent. + * + * Also, the same as existing buffers, 'dotnet' and 'native' are just handles + * and don't actually mean anything to dlog (i.e. logs can end up there from any + * program, not just .NET/native programs), though of course whoever uses these + * sinks will likely want to use them accordingly. */ -#define SINKS_MAX (LOG_ID_MAX) +#define SINK_DOTNET (LOG_ID_MAX) +#define SINK_NATIVE (LOG_ID_MAX + 1) +#define SINKS_MAX (LOG_ID_MAX + 2) diff --git a/src/libdlog/log.c b/src/libdlog/log.c index 5cfb00f..1a09bd3 100644 --- a/src/libdlog/log.c +++ b/src/libdlog/log.c @@ -808,6 +808,38 @@ EXPORT_API int dlog_print(log_priority prio, const char *tag, const char *fmt, . return ret; } +EXPORT_API int dlog_vprint_dotnet(log_priority prio, const char *tag, const char *fmt, va_list ap) +{ + return __write_to_log(SINK_DOTNET, prio, tag, fmt, ap, false, false); +} + +EXPORT_API int dlog_print_dotnet(log_priority prio, const char *tag, const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + int ret = dlog_vprint_dotnet(prio, tag, fmt, ap); + va_end(ap); + + return ret; +} + +EXPORT_API int dlog_vprint_native(log_priority prio, const char *tag, const char *fmt, va_list ap) +{ + return __write_to_log(SINK_NATIVE, prio, tag, fmt, ap, false, false); +} + +EXPORT_API int dlog_print_native(log_priority prio, const char *tag, const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + int ret = dlog_vprint_native(prio, tag, fmt, ap); + va_end(ap); + + return ret; +} + /** * @brief Finalize DLog * @details Finalizes and deallocates the library diff --git a/src/logsend/logsend.c b/src/logsend/logsend.c index 855a89c..c31fd6c 100644 --- a/src/logsend/logsend.c +++ b/src/logsend/logsend.c @@ -93,6 +93,10 @@ int send_log(struct parsed_params *params) ret = (dlog_error_e) __dlog_critical_print(params->buffer, params->priority, params->tag, "%s", params->msg); else if (params->secure) ret = (dlog_error_e) __dlog_sec_print(params->buffer, params->priority, params->tag, "%s", params->msg); + else if (params->buffer == SINK_DOTNET) + ret = (dlog_error_e) dlog_print_dotnet( /* apps */ params->priority, params->tag, "%s", params->msg); + else if (params->buffer == SINK_NATIVE) + ret = (dlog_error_e) dlog_print_native( /* apps */ params->priority, params->tag, "%s", params->msg); else ret = (dlog_error_e) __dlog_print(params->buffer, params->priority, params->tag, "%s", params->msg); if (ret < 0) { @@ -134,7 +138,7 @@ void print_help(const char *progname) "\t \tfirst letter is enough; defaults to Info\n" "\t-b buffer \tone of {main, system, radio, apps}\n" "\t \tdefaults to apps\n" - "\t-b sink \t(currently none available)\n" + "\t-b sink \tone of {dotnet_api, native_api}\n" "\t \textra sinks that use different dlog interfaces\n" "\t-t tag \ta short identification string for identification and filtering purposes\n" "\t \tcan be anything, defaults to DLOG_SEND\n" diff --git a/src/shared/buffer_traits.c b/src/shared/buffer_traits.c index 3eeda96..ce448ef 100644 --- a/src/shared/buffer_traits.c +++ b/src/shared/buffer_traits.c @@ -37,6 +37,8 @@ static const struct { [LOG_ID_APPS ] = { .name = "apps" , .core = true, .platform = false, .extra_sink = false, .sink_redirect = LOG_ID_APPS }, [LOG_ID_KMSG ] = { .name = "kmsg" , .core = false, .platform = false, .extra_sink = false, .sink_redirect = LOG_ID_KMSG }, [LOG_ID_SYSLOG] = { .name = "syslog" , .core = false, .platform = false, .extra_sink = false, .sink_redirect = LOG_ID_SYSLOG }, + [SINK_DOTNET ] = { .name = "dotnet_api", .core = false, .platform = false, .extra_sink = true, .sink_redirect = LOG_ID_APPS }, + [SINK_NATIVE ] = { .name = "native_api", .core = false, .platform = false, .extra_sink = true, .sink_redirect = LOG_ID_APPS }, }; bool is_buffer_valid(log_id_t id) diff --git a/src/tests/logctl.c b/src/tests/logctl.c index 5c463d2..bbb345b 100644 --- a/src/tests/logctl.c +++ b/src/tests/logctl.c @@ -272,6 +272,8 @@ void test_handle_plog(void) "enable_apps=1", "enable_kmsg=1", "enable_syslog=1", + "enable_dotnet_api=1", + "enable_native_api=1", }; struct parsed_params pp; diff --git a/tests/dlog_test.in b/tests/dlog_test.in index 3c3eecc..64c240e 100644 --- a/tests/dlog_test.in +++ b/tests/dlog_test.in @@ -329,6 +329,71 @@ if [ "$type" = "pipe" ] && [ "$quick" -ne 1 ]; then [ "$(dlogutil -d DLOGSEND_SIGPIPE_TEST | wc -l)" -eq 2 ] && ok || fail fi +dlogutil -c + +LOG_DETAILS="testing if dlogutil rejects dotnet" +dlogutil -db dotnet_api && fail || ok + +LOG_DETAILS="testing if dlogutil rejects native" +dlogutil -db native_api && fail || ok + +LOG_DETAILS="testing if dotnet redirects to regular apps (1/2)" +dlogsend -b dotnet_api "TEST" +sleep 0.25 +[ "$(dlogutil -d -b apps | wc -l)" -eq 1 ] && ok || fail + +LOG_DETAILS="testing if dotnet redirects to regular apps (2/2)" +dlogsend -c 6 -b dotnet_api "TEST" +sleep 0.25 +[ "$(dlogutil -d -b apps | wc -l)" -eq 7 ] && ok || fail + +LOG_DETAILS="testing if native redirects to regular apps (1/2)" +dlogsend -b native_api "TEST" +sleep 0.25 +[ "$(dlogutil -d -b apps | wc -l)" -eq 8 ] && ok || fail + +LOG_DETAILS="testing if native redirects to regular apps (2/2)" +dlogsend -c 6 -b native_api "TEST" +sleep 0.25 +[ "$(dlogutil -d -b apps | wc -l)" -eq 14 ] && ok || fail + +dlogutil -c +LOG_DETAILS="testing if blocking dotnet and regular apps is separate (1/4)" +dlogctl -b apps --enable +dlogctl -b dotnet_api --disable +dlogsend -b dotnet_api "TEST" +[ "$(dlogutil -d -b apps | wc -l)" -eq 0 ] && ok || fail +LOG_DETAILS="testing if blocking dotnet and regular apps is separate (2/4)" +dlogsend -b apps "TEST" +[ "$(dlogutil -d -b apps | wc -l)" -eq 1 ] && ok || fail +LOG_DETAILS="testing if blocking dotnet and regular apps is separate (3/4)" +dlogctl -b apps --disable +dlogctl -b dotnet_api --enable +dlogsend -b dotnet_api "TEST" +[ "$(dlogutil -d -b apps | wc -l)" -eq 2 ] && ok || fail +LOG_DETAILS="testing if blocking dotnet and regular apps is separate (4/4)" +dlogsend -b apps "TEST" +[ "$(dlogutil -d -b apps | wc -l)" -eq 2 ] && ok || fail + + +dlogutil -c +LOG_DETAILS="testing if blocking native and regular apps is separate (1/4)" +dlogctl -b apps --enable +dlogctl -b native_api --disable +dlogsend -b native_api "TEST" +[ "$(dlogutil -d -b apps | wc -l)" -eq 0 ] && ok || fail +LOG_DETAILS="testing if blocking native and regular apps is separate (2/4)" +dlogsend -b apps "TEST" +[ "$(dlogutil -d -b apps | wc -l)" -eq 1 ] && ok || fail +LOG_DETAILS="testing if blocking native and regular apps is separate (3/4)" +dlogctl -b apps --disable +dlogctl -b native_api --enable +dlogsend -b native_api "TEST" +[ "$(dlogutil -d -b apps | wc -l)" -eq 2 ] && ok || fail +LOG_DETAILS="testing if blocking native and regular apps is separate (4/4)" +dlogsend -b apps "TEST" +[ "$(dlogutil -d -b apps | wc -l)" -eq 2 ] && ok || fail + # put 100 log entries in the "main" buffer dlogutil -c test_libdlog 100