Skip to content

Commit 866fc93

Browse files
authored
refactor: introduce mandatory log level and enhance logging functionality across components (#776)
1 parent 23ccce8 commit 866fc93

File tree

20 files changed

+230
-83
lines changed

20 files changed

+230
-83
lines changed

.vscode/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@
137137
"request": "launch",
138138
"program": "${workspaceFolder}/out/linux/x64/tests/standalone/ten_runtime_smoke_test",
139139
"args": [
140-
"--gtest_filter=BasicTest.ThrowExceptionInExtension"
140+
"--gtest_filter=BasicTest.EmptyExtensionGroup"
141141
],
142142
"cwd": "${workspaceFolder}/out/linux/x64/tests/standalone/",
143143
"env": {

core/include/ten_utils/log/log.h

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -50,42 +50,6 @@
5050
__FILE__, __LINE__, __VA_ARGS__); \
5151
} while (0)
5252

53-
#define TEN_LOGV_AUX(log, ...) \
54-
do { \
55-
ten_log_log_formatted(log, TEN_LOG_LEVEL_VERBOSE, __func__, __FILE__, \
56-
__LINE__, __VA_ARGS__); \
57-
} while (0)
58-
59-
#define TEN_LOGD_AUX(log, ...) \
60-
do { \
61-
ten_log_log_formatted(log, TEN_LOG_LEVEL_DEBUG, __func__, __FILE__, \
62-
__LINE__, __VA_ARGS__); \
63-
} while (0)
64-
65-
#define TEN_LOGI_AUX(log, ...) \
66-
do { \
67-
ten_log_log_formatted(log, TEN_LOG_LEVEL_INFO, __func__, __FILE__, \
68-
__LINE__, __VA_ARGS__); \
69-
} while (0)
70-
71-
#define TEN_LOGW_AUX(log, ...) \
72-
do { \
73-
ten_log_log_formatted(log, TEN_LOG_LEVEL_WARN, __func__, __FILE__, \
74-
__LINE__, __VA_ARGS__); \
75-
} while (0)
76-
77-
#define TEN_LOGE_AUX(log, ...) \
78-
do { \
79-
ten_log_log_formatted(log, TEN_LOG_LEVEL_ERROR, __func__, __FILE__, \
80-
__LINE__, __VA_ARGS__); \
81-
} while (0)
82-
83-
#define TEN_LOGF_AUX(log, ...) \
84-
do { \
85-
ten_log_log_formatted(log, TEN_LOG_LEVEL_FATAL, __func__, __FILE__, \
86-
__LINE__, __VA_ARGS__); \
87-
} while (0)
88-
8953
typedef struct ten_string_t ten_string_t;
9054
typedef struct ten_log_t ten_log_t;
9155

@@ -98,6 +62,8 @@ typedef enum TEN_LOG_LEVEL {
9862
TEN_LOG_LEVEL_WARN,
9963
TEN_LOG_LEVEL_ERROR,
10064
TEN_LOG_LEVEL_FATAL,
65+
66+
TEN_LOG_LEVEL_MANDATORY,
10167
} TEN_LOG_LEVEL;
10268

10369
typedef enum TEN_LOG_OUTPUT_TYPE {

core/include_internal/ten_runtime/engine/engine.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ struct ten_engine_t {
6161
// into the engine until it is fully prepared.
6262
bool is_ready_to_handle_msg;
6363

64+
ten_string_t graph_name;
65+
6466
// When app creates an engine, it will create a randomized graph ID for the
6567
// engine. It _must_ be a UUID4 string.
6668
ten_string_t graph_id;
@@ -118,6 +120,9 @@ TEN_RUNTIME_PRIVATE_API bool ten_engine_is_ready_to_handle_msg(
118120
TEN_RUNTIME_PRIVATE_API const char *ten_engine_get_id(ten_engine_t *self,
119121
bool check_thread);
120122

123+
TEN_RUNTIME_PRIVATE_API void ten_engine_set_graph_name(ten_engine_t *self,
124+
const char *name);
125+
121126
TEN_RUNTIME_PRIVATE_API void ten_engine_add_orphan_connection(
122127
ten_engine_t *self, ten_connection_t *connection);
123128

core/include_internal/ten_runtime/extension_thread/extension_thread.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ typedef struct ten_extension_thread_t {
4646
ten_signature_t signature;
4747
ten_sanitizer_thread_check_t thread_check;
4848

49+
int64_t tid;
50+
4951
TEN_EXTENSION_THREAD_STATE state;
5052
bool is_close_triggered;
5153

core/include_internal/ten_utils/log/log.h

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,54 @@
1616

1717
#define TEN_LOG_SIGNATURE 0xC0EE0CE92149D61AU
1818

19+
#define TEN_LOGM(...) \
20+
do { \
21+
ten_log_log_formatted(&ten_global_log, TEN_LOG_LEVEL_MANDATORY, __func__, \
22+
__FILE__, __LINE__, __VA_ARGS__); \
23+
} while (0)
24+
25+
#define TEN_LOGV_AUX(log, ...) \
26+
do { \
27+
ten_log_log_formatted(log, TEN_LOG_LEVEL_VERBOSE, __func__, __FILE__, \
28+
__LINE__, __VA_ARGS__); \
29+
} while (0)
30+
31+
#define TEN_LOGD_AUX(log, ...) \
32+
do { \
33+
ten_log_log_formatted(log, TEN_LOG_LEVEL_DEBUG, __func__, __FILE__, \
34+
__LINE__, __VA_ARGS__); \
35+
} while (0)
36+
37+
#define TEN_LOGI_AUX(log, ...) \
38+
do { \
39+
ten_log_log_formatted(log, TEN_LOG_LEVEL_INFO, __func__, __FILE__, \
40+
__LINE__, __VA_ARGS__); \
41+
} while (0)
42+
43+
#define TEN_LOGW_AUX(log, ...) \
44+
do { \
45+
ten_log_log_formatted(log, TEN_LOG_LEVEL_WARN, __func__, __FILE__, \
46+
__LINE__, __VA_ARGS__); \
47+
} while (0)
48+
49+
#define TEN_LOGE_AUX(log, ...) \
50+
do { \
51+
ten_log_log_formatted(log, TEN_LOG_LEVEL_ERROR, __func__, __FILE__, \
52+
__LINE__, __VA_ARGS__); \
53+
} while (0)
54+
55+
#define TEN_LOGF_AUX(log, ...) \
56+
do { \
57+
ten_log_log_formatted(log, TEN_LOG_LEVEL_FATAL, __func__, __FILE__, \
58+
__LINE__, __VA_ARGS__); \
59+
} while (0)
60+
61+
#define TEN_LOGM_AUX(log, ...) \
62+
do { \
63+
ten_log_log_formatted(log, TEN_LOG_LEVEL_MANDATORY, __func__, __FILE__, \
64+
__LINE__, __VA_ARGS__); \
65+
} while (0)
66+
1967
typedef struct ten_string_t ten_string_t;
2068

2169
TEN_UTILS_PRIVATE_API bool ten_log_check_integrity(ten_log_t *self);

core/include_internal/ten_utils/log/termcolor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@
1616
#define TEN_LOG_COLOR_MAGENTA "\033[35m"
1717
#define TEN_LOG_COLOR_CYAN "\033[36m"
1818
#define TEN_LOG_COLOR_WHITE "\033[37m"
19+
#define TEN_LOG_COLOR_GOLD "\033[1;33m"

core/src/ten_manager/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ pub mod fs;
3333
pub mod graph;
3434
pub mod http;
3535
mod install;
36+
pub mod log;
3637
mod manifest_lock;
3738
pub mod output;
3839
mod package_file;

core/src/ten_manager/src/log/mod.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//
2+
// Copyright © 2025 Agora
3+
// This file is part of TEN Framework, an open source project.
4+
// Licensed under the Apache License, Version 2.0, with certain conditions.
5+
// Refer to the "LICENSE" file in the root directory for more information.
6+
//
7+
use anyhow::Result;
8+
use std::collections::HashMap;
9+
10+
pub struct ExtensionInfo {
11+
pub thread_id: u64,
12+
}
13+
14+
pub struct GraphResourcesLog {
15+
pub app_uri: Option<String>,
16+
pub graph_id: String,
17+
pub graph_name: String,
18+
pub extensions: HashMap<String, ExtensionInfo>,
19+
}
20+
21+
pub fn parse_graph_resources_log(
22+
log_message: &str,
23+
graph_resources_log: &mut GraphResourcesLog,
24+
) -> Result<()> {
25+
Ok(())
26+
}

core/src/ten_runtime/app/predefined_graph.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,13 +228,17 @@ bool ten_app_start_predefined_graph(
228228

229229
ten_path_t *out_path = (ten_path_t *)ten_path_table_add_out_path(
230230
self->path_table, start_graph_cmd);
231-
TEN_ASSERT(out_path && ten_path_check_integrity(out_path, true),
232-
"Should not happen.");
231+
TEN_ASSERT(out_path, "Should not happen.");
232+
TEN_ASSERT(ten_path_check_integrity(out_path, true), "Should not happen.");
233233
}
234234
// @}
235235

236236
predefined_graph_info->engine = ten_app_create_engine(self, start_graph_cmd);
237237

238+
ten_engine_set_graph_name(
239+
predefined_graph_info->engine,
240+
ten_string_get_raw_str(&predefined_graph_info->name));
241+
238242
// There is no 'connection' when creating predefined graph, so it's always no
239243
// migration in this stage. Send the 'start_graph_cmd' into the newly created
240244
// engine directly.

core/src/ten_runtime/engine/engine.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ static void ten_engine_destroy(ten_engine_t *self) {
9595
self->cmd_stop_graph = NULL;
9696
}
9797

98+
ten_string_deinit(&self->graph_name);
9899
ten_string_deinit(&self->graph_id);
99100

100101
ten_path_table_destroy(self->path_table);
@@ -125,6 +126,7 @@ static void ten_engine_set_graph_id(ten_engine_t *self, ten_shared_ptr_t *cmd) {
125126
!ten_string_is_empty(src_graph_id)) {
126127
TEN_LOGD("[%s] Inherit engine's name from previous node",
127128
ten_string_get_raw_str(src_graph_id));
129+
128130
ten_string_init_formatted(&self->graph_id, "%s",
129131
ten_string_get_raw_str(src_graph_id));
130132
} else {
@@ -216,6 +218,7 @@ ten_engine_t *ten_engine_create(ten_app_t *app, ten_shared_ptr_t *cmd) {
216218

217219
self->long_running_mode = ten_cmd_start_graph_get_long_running_mode(cmd);
218220

221+
ten_string_init(&self->graph_name);
219222
ten_engine_set_graph_id(self, cmd);
220223

221224
ten_engine_init_individual_eventloop_relevant_vars(self, app);
@@ -253,6 +256,14 @@ const char *ten_engine_get_id(ten_engine_t *self, bool check_thread) {
253256
return ten_string_get_raw_str(&self->graph_id);
254257
}
255258

259+
void ten_engine_set_graph_name(ten_engine_t *self, const char *name) {
260+
TEN_ASSERT(self, "Should not happen.");
261+
TEN_ASSERT(ten_engine_check_integrity(self, false), "Should not happen.");
262+
TEN_ASSERT(name, "Should not happen.");
263+
264+
ten_string_set_from_c_str(&self->graph_name, name);
265+
}
266+
256267
void ten_engine_del_orphan_connection(ten_engine_t *self,
257268
ten_connection_t *connection) {
258269
TEN_ASSERT(self, "Should not happen.");

0 commit comments

Comments
 (0)