Skip to content
This repository was archived by the owner on Dec 26, 2022. It is now read-only.

Commit 8d75119

Browse files
authored
Merge pull request #465 from HowJMay/verbose
Turn off logger after initialization and set verbose mode by default
2 parents 8e6e2ea + 410186f commit 8d75119

File tree

7 files changed

+35
-33
lines changed

7 files changed

+35
-33
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,13 @@ Tangle-accelerator is built and launched through Bazel, it also requires Redis t
8989

9090
## Build from Source
9191

92-
Before running tangle-accelerator, please edit binding address/port of accelerator instance, IRI, and redis server in `accelerator/config.h` unless they are all localhost and/or you don't want to provide external connection. With dependency of [entangled](https://github.com/iotaledger/entangled), IRI address doesn't support https at the moment. Here are some configurations you might need to change:
92+
Before running tangle-accelerator, please edit binding address/port of accelerator instance, IRI, and redis server in `accelerator/config.h` unless they are all localhost and/or you don't want to provide external connection. With dependency of [entangled](https://github.com/iotaledger/entangled), IRI address doesn't support https at the moment. Here are some configurations and command you might need to change and use:
9393

9494
* `TA_HOST`: binding address of accelerator instance
9595
* `TA_PORT`: port of accelerator instance
9696
* `IRI_HOST`: binding address of IRI
9797
* `IRI_PORT`: port of IRI
98+
* `quiet`: Turn off logging message
9899

99100
```
100101
$ make && bazel run //accelerator

accelerator/cli_info.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ typedef enum ta_cli_arg_value_e {
5050
PROXY_API,
5151

5252
/** LOGGER */
53-
VERBOSE,
53+
QUIET,
5454
} ta_cli_arg_value_t;
5555

5656
static struct ta_cli_argument_s {
@@ -78,7 +78,7 @@ static struct ta_cli_argument_s {
7878
{"cache", required_argument, NULL, CACHE, "Enable cache server with Y"},
7979
{"config", required_argument, NULL, CONF_CLI, "Read configuration file"},
8080
{"proxy_passthrough", no_argument, NULL, PROXY_API, "Pass proxy API directly to IRI without processing"},
81-
{"verbose", no_argument, NULL, VERBOSE, "Enable logger"},
81+
{"quiet", no_argument, NULL, QUIET, "Disable logger"},
8282
{NULL, 0, NULL, 0, NULL}};
8383

8484
static const int cli_cmd_num = sizeof(ta_cli_arguments_g) / sizeof(struct ta_cli_argument_s);

accelerator/config.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,9 @@ static status_t cli_core_set(ta_core_t* const core, int key, char* const value)
106106
cache->cache_state = (toupper(value[0]) == 'T');
107107
break;
108108

109-
// Verbose configuration
110-
case VERBOSE:
111-
verbose_mode = (toupper(value[0]) == 'T');
109+
// Quiet mode configuration
110+
case QUIET:
111+
quiet_mode = (toupper(value[0]) == 'T');
112112
break;
113113

114114
case PROXY_API:
@@ -175,8 +175,8 @@ status_t ta_core_default_init(ta_core_t* const core) {
175175
ta_log_info("Initializing DB connection\n");
176176
db_service->host = strdup(DB_HOST);
177177
#endif
178-
// Turn off verbose mode default
179-
verbose_mode = false;
178+
// Turn off quiet mode default
179+
quiet_mode = false;
180180

181181
return ret;
182182
}
@@ -303,9 +303,9 @@ status_t ta_core_cli_init(ta_core_t* const core, int argc, char** argv) {
303303
case 'v':
304304
printf("%s\n", TA_VERSION);
305305
exit(EXIT_SUCCESS);
306-
case VERBOSE:
307-
// Turn on verbose mode
308-
verbose_mode = true;
306+
case QUIET:
307+
// Turn on quiet mode
308+
quiet_mode = true;
309309

310310
// Enable backend_redis logger
311311
br_logger_init();

accelerator/core/serializer/serializer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ status_t ta_get_info_serialize(char** obj, ta_config_t* const ta_config, iota_co
4646
cJSON_AddNumberToObject(json_root, "redis_port", cache->port);
4747
cJSON_AddNumberToObject(json_root, "milestone_depth", tangle->milestone_depth);
4848
cJSON_AddNumberToObject(json_root, "mwm", tangle->mwm);
49-
cJSON_AddBoolToObject(json_root, "verbose", verbose_mode);
49+
cJSON_AddBoolToObject(json_root, "quiet", quiet_mode);
5050

5151
*obj = cJSON_PrintUnformatted(json_root);
5252
if (*obj == NULL) {

accelerator/main.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,19 +55,6 @@ int main(int argc, char* argv[]) {
5555
return EXIT_FAILURE;
5656
}
5757

58-
// Enable other loggers when verbose mode is on
59-
if (verbose_mode) {
60-
http_logger_init();
61-
apis_logger_init();
62-
cc_logger_init();
63-
pow_logger_init();
64-
timer_logger_init();
65-
} else {
66-
// Destroy logger when verbose mode is off
67-
logger_helper_release(logger_id);
68-
logger_helper_destroy();
69-
}
70-
7158
if (ta_http_init(&ta_http, &ta_core) != SC_OK) {
7259
ta_log_error("HTTP initialization failed %s.\n", MAIN_LOGGER);
7360
return EXIT_FAILURE;
@@ -80,6 +67,19 @@ int main(int argc, char* argv[]) {
8067

8168
log_info(logger_id, "Tangle-accelerator starts running\n");
8269

70+
// Disable loggers when quiet mode is on
71+
if (quiet_mode) {
72+
// Destroy logger when quiet mode is on
73+
logger_helper_release(logger_id);
74+
logger_helper_destroy();
75+
} else {
76+
http_logger_init();
77+
apis_logger_init();
78+
cc_logger_init();
79+
pow_logger_init();
80+
timer_logger_init();
81+
}
82+
8383
/* pause() cause TA to sleep until it catch a signal,
8484
* also the return value and errno should be -1 and EINTR on success.
8585
*/
@@ -98,7 +98,7 @@ int main(int argc, char* argv[]) {
9898
log_info(logger_id, "Destroying TA configurations\n");
9999
ta_core_destroy(&ta_core);
100100

101-
if (verbose_mode) {
101+
if (quiet_mode == false) {
102102
http_logger_release();
103103
apis_logger_release();
104104
cc_logger_release();

accelerator/mqtt_main.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,12 @@ int main(int argc, char *argv[]) {
4242
return EXIT_FAILURE;
4343
}
4444

45-
if (verbose_mode) {
45+
// Disable loggers when quiet mode is on
46+
if (quiet_mode) {
47+
// Destroy logger when quiet mode is on
48+
logger_helper_release(logger_id);
49+
logger_helper_destroy();
50+
} else {
4651
mqtt_utils_logger_init();
4752
mqtt_common_logger_init();
4853
mqtt_callback_logger_init();
@@ -52,10 +57,6 @@ int main(int argc, char *argv[]) {
5257
cc_logger_init();
5358
pow_logger_init();
5459
timer_logger_init();
55-
} else {
56-
// Destroy logger when verbose mode is off
57-
logger_helper_release(logger_id);
58-
logger_helper_destroy();
5960
}
6061

6162
// Initialize `mosq` and `cfg`
@@ -98,7 +99,7 @@ int main(int argc, char *argv[]) {
9899
mosquitto_lib_cleanup();
99100
mosq_config_free(&cfg);
100101

101-
if (verbose_mode) {
102+
if (quiet_mode == false) {
102103
mqtt_utils_logger_release();
103104
mqtt_common_logger_release();
104105
mqtt_callback_logger_release();

common/logger.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ static inline status_t ta_logger_init() {
7070
fflush(stdout); \
7171
} while (0)
7272

73-
bool verbose_mode; /**< flag of verbose mode */
73+
bool quiet_mode; /**< flag of quiet mode */
7474

7575
#ifdef __cplusplus
7676
}

0 commit comments

Comments
 (0)