Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 53 additions & 1 deletion core/include/ten_utils/log/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,63 @@ typedef void (*ten_log_encrypt_on_encrypt_func_t)(uint8_t *data,
void *user_data);
typedef void (*ten_log_encrypt_on_deinit_func_t)(void *user_data);

/**
* @brief Structure to pass location information to log functions.
*
* This structure contains the location context (app_uri, graph_id,
* extension_name) for a log message. It's designed for efficient FFI passing
* between C and Rust.
*
* @warning CRITICAL: Keep in sync with Rust definition
*
* This struct MUST exactly match the Rust struct `TenLogLocInfo` defined in:
* `core/src/ten_rust/src/log/bindings.rs`
*
* Rust Definition (for reference):
* @code{.rs}
* #[repr(C)]
* pub struct TenLogLocInfo {
* pub app_uri: *const c_char,
* pub app_uri_len: usize,
* pub graph_id: *const c_char,
* pub graph_id_len: usize,
* pub extension_name: *const c_char,
* pub extension_name_len: usize,
* }
* @endcode
*
* @note Memory Layout Requirements:
* - Field order must match exactly
* - Field types must have same size and alignment
* - No padding should be introduced between fields (naturally aligned)
* - On 64-bit: sizeof = 48 bytes, On 32-bit: sizeof = 24 bytes
*
* @note Safety:
* - Modifying this struct requires updating the Rust definition
* - Modifying the Rust definition requires updating this struct
* - Rust has compile-time assertions to verify layout compatibility
*
* @note Verification:
* - Run Rust test: `cargo test test_ten_log_loc_info_layout`
* - The test verifies size, alignment, and field offsets
*
* @see TenLogLocInfo in core/src/ten_rust/src/log/bindings.rs
*/
typedef struct ten_log_loc_info_t {
const char *app_uri;
size_t app_uri_len;
const char *graph_id;
size_t graph_id_len;
const char *extension_name;
size_t extension_name_len;
} ten_log_loc_info_t;

typedef void (*ten_log_advanced_log_func_t)(
ten_log_t *self, TEN_LOG_LEVEL level, const char *category,
size_t category_len, const char *func_name, size_t func_name_len,
const char *file_name, size_t file_name_len, size_t line_no,
const char *msg, size_t msg_len, ten_value_t *fields);
const char *msg, size_t msg_len, ten_value_t *fields,
const ten_log_loc_info_t *loc_info);

typedef void (*ten_log_advanced_log_reopen_all_func_t)(ten_log_t *self,
void *config);
Expand Down
5 changes: 5 additions & 0 deletions core/include_internal/ten_runtime/common/loc.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <stdbool.h>

#include "ten_utils/lib/string.h"
#include "ten_utils/log/log.h"
#include "ten_utils/value/value.h"

#define TEN_LOC_SIGNATURE 0x581B639EF70CBC5DU
Expand Down Expand Up @@ -141,3 +142,7 @@ TEN_RUNTIME_PRIVATE_API void ten_loc_set_extension_name_with_size(

TEN_RUNTIME_PRIVATE_API void ten_loc_set_extension_name(
ten_loc_t *self, const char *extension_name);

// Helper function to initialize ten_log_loc_info_t from ten_loc_t.
TEN_RUNTIME_PRIVATE_API void ten_log_loc_info_init_from_loc(
ten_log_loc_info_t *info, ten_loc_t *loc);
3 changes: 2 additions & 1 deletion core/include_internal/ten_runtime/global/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ TEN_RUNTIME_PRIVATE_API void ten_log_rust_log_func(
ten_log_t *self, TEN_LOG_LEVEL level, const char *category,
size_t category_len, const char *func_name, size_t func_name_len,
const char *file_name, size_t file_name_len, size_t line_no,
const char *msg, size_t msg_len, ten_value_t *fields);
const char *msg, size_t msg_len, ten_value_t *fields,
const ten_log_loc_info_t *loc_info);

TEN_RUNTIME_PRIVATE_API void ten_log_rust_config_deinit(void *config);

Expand Down
5 changes: 5 additions & 0 deletions core/include_internal/ten_runtime/ten_env/ten_env.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

typedef struct ten_engine_t ten_engine_t;
typedef struct ten_addon_loader_t ten_addon_loader_t;
typedef struct ten_loc_t ten_loc_t;

typedef void (*ten_env_destroy_handler_in_target_lang_func_t)(
void *me_in_target_lang);
Expand Down Expand Up @@ -115,6 +116,10 @@ TEN_RUNTIME_PRIVATE_API void ten_env_set_attach_to(
TEN_RUNTIME_PRIVATE_API const char *ten_env_get_attached_instance_name(
ten_env_t *self, bool check_thread);

TEN_RUNTIME_PRIVATE_API void ten_env_get_attached_target_loc(ten_env_t *self,
ten_loc_t *loc,
bool check_thread);

TEN_RUNTIME_PRIVATE_API ten_app_t *ten_env_get_belonging_app(ten_env_t *self);

inline ten_extension_t *ten_env_get_attached_extension(ten_env_t *self) {
Expand Down
3 changes: 2 additions & 1 deletion core/include_internal/ten_rust/ten_rust.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,8 @@ TEN_RUST_PRIVATE_API void ten_rust_log(
AdvancedLogConfig *config, const char *category, size_t category_len,
int64_t pid, int64_t tid, int level, const char *func_name,
size_t func_name_len, const char *file_name, size_t file_name_len,
size_t line_no, const char *msg, size_t msg_len);
size_t line_no, const ten_log_loc_info_t *loc_info, const char *msg,
size_t msg_len);

TEN_RUST_PRIVATE_API void ten_rust_log_config_destroy(
AdvancedLogConfig *config);
6 changes: 4 additions & 2 deletions core/include_internal/ten_utils/log/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,15 @@ TEN_UTILS_PRIVATE_API const char *filename(const char *path, size_t path_len,
TEN_UTILS_API void ten_log_log(ten_log_t *self, TEN_LOG_LEVEL level,
const char *func_name, const char *file_name,
size_t line_no, const char *msg,
const char *category, ten_value_t *fields);
const char *category, ten_value_t *fields,
const ten_log_loc_info_t *loc_info);

TEN_UTILS_API void ten_log_log_with_size(
ten_log_t *self, TEN_LOG_LEVEL level, const char *func_name,
size_t func_name_len, const char *file_name, size_t file_name_len,
size_t line_no, const char *msg, size_t msg_len, const char *category,
size_t category_len, ten_value_t *fields);
size_t category_len, ten_value_t *fields,
const ten_log_loc_info_t *loc_info);

TEN_UTILS_API void ten_log_global_init(bool enable_advanced_log);

Expand Down
Loading
Loading