1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-11-22 21:13:02 +01:00

Add option for toxcore logging in stderr

This commit is contained in:
jfreegman 2020-05-04 16:15:24 -04:00
parent 16d96d6faf
commit 4bfb344caa
No known key found for this signature in database
GPG Key ID: 3627F3144076AE63
4 changed files with 35 additions and 4 deletions

View File

@ -78,6 +78,11 @@ instead of
Show help message Show help message
.RE .RE
.PP .PP
\-l, \-\-logging
.RS 4
Enable toxcore logging to stderr
.RE
.PP
\-n, \-\-nodes nodes\-file \-n, \-\-nodes nodes\-file
.RS 4 .RS 4
Use specified Use specified

View File

@ -40,6 +40,9 @@ OPTIONS
-h, --help:: -h, --help::
Show help message Show help message
-l, --logging::
Enable toxcore logging to stderr
-n, --nodes nodes-file:: -n, --nodes nodes-file::
Use specified 'nodes-file' for DHT bootstrap nodes instead of '~/.config/tox/DHTnodes.json' Use specified 'nodes-file' for DHT bootstrap nodes instead of '~/.config/tox/DHTnodes.json'

View File

@ -219,6 +219,16 @@ void exit_toxic_err(const char *errmsg, int errcode)
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
void cb_toxcore_logger(Tox *m, TOX_LOG_LEVEL level, const char *file, uint32_t line, const char *func,
const char *message, void *user_data)
{
UNUSED_VAR(user_data);
UNUSED_VAR(file);
UNUSED_VAR(m);
fprintf(stderr, "[%d] %u:%s() - %s\n", level, line, func, message);
}
static void init_term(void) static void init_term(void)
{ {
#if HAVE_WIDECHAR #if HAVE_WIDECHAR
@ -645,6 +655,10 @@ static void init_tox_options(struct Tox_Options *tox_opts)
tox_options_set_proxy_type(tox_opts, arg_opts.proxy_type); tox_options_set_proxy_type(tox_opts, arg_opts.proxy_type);
tox_options_set_tcp_port(tox_opts, arg_opts.tcp_port); tox_options_set_tcp_port(tox_opts, arg_opts.tcp_port);
if (arg_opts.logging) {
tox_options_set_log_callback(tox_opts, cb_toxcore_logger);
}
if (!tox_options_get_ipv6_enabled(tox_opts)) { if (!tox_options_get_ipv6_enabled(tox_opts)) {
queue_init_message("Forcing IPv4 connection"); queue_init_message("Forcing IPv4 connection");
} }
@ -942,6 +956,7 @@ static void print_usage(void)
fprintf(stderr, " -e, --encrypt-data Encrypt an unencrypted data file\n"); fprintf(stderr, " -e, --encrypt-data Encrypt an unencrypted data file\n");
fprintf(stderr, " -f, --file Use specified data file\n"); fprintf(stderr, " -f, --file Use specified data file\n");
fprintf(stderr, " -h, --help Show this message and exit\n"); fprintf(stderr, " -h, --help Show this message and exit\n");
fprintf(stderr, " -l, --logging Enable toxcore logging to stderr\n");
fprintf(stderr, " -n, --nodes Use specified DHTnodes file\n"); fprintf(stderr, " -n, --nodes Use specified DHTnodes file\n");
fprintf(stderr, " -o, --noconnect Do not connect to the DHT network\n"); fprintf(stderr, " -o, --noconnect Do not connect to the DHT network\n");
fprintf(stderr, " -p, --SOCKS5-proxy Use SOCKS5 proxy: Requires [IP] [port]\n"); fprintf(stderr, " -p, --SOCKS5-proxy Use SOCKS5 proxy: Requires [IP] [port]\n");
@ -978,6 +993,7 @@ static void parse_args(int argc, char *argv[])
{"default-locale", no_argument, 0, 'd'}, {"default-locale", no_argument, 0, 'd'},
{"config", required_argument, 0, 'c'}, {"config", required_argument, 0, 'c'},
{"encrypt-data", no_argument, 0, 'e'}, {"encrypt-data", no_argument, 0, 'e'},
{"logging", no_argument, 0, 'l'},
{"nodes", required_argument, 0, 'n'}, {"nodes", required_argument, 0, 'n'},
{"help", no_argument, 0, 'h'}, {"help", no_argument, 0, 'h'},
{"noconnect", no_argument, 0, 'o'}, {"noconnect", no_argument, 0, 'o'},
@ -991,7 +1007,7 @@ static void parse_args(int argc, char *argv[])
{NULL, no_argument, NULL, 0}, {NULL, no_argument, NULL, 0},
}; };
const char *opts_str = "4bdehotuxvc:f:n:r:p:P:T:"; const char *opts_str = "4bdehlotuxvc:f:n:r:p:P:T:";
int opt, indexptr; int opt, indexptr;
long int port = 0; long int port = 0;
@ -1055,6 +1071,12 @@ static void parse_args(int argc, char *argv[])
break; break;
case 'l':
arg_opts.debug = true;
arg_opts.logging = true;
queue_init_message("Toxcore logging enabled to stderr");
break;
case 'n': case 'n':
snprintf(arg_opts.nodes_path, sizeof(arg_opts.nodes_path), "%s", optarg); snprintf(arg_opts.nodes_path, sizeof(arg_opts.nodes_path), "%s", optarg);
break; break;
@ -1248,6 +1270,9 @@ void DnD_callback(const char *asdv, DropType dt)
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
/* Make sure all written files are read/writeable only by the current user. */
umask(S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
parse_args(argc, argv); parse_args(argc, argv);
/* Use the -b flag to enable stderr */ /* Use the -b flag to enable stderr */
@ -1263,9 +1288,6 @@ int main(int argc, char **argv)
queue_init_message("Warning: Using --unencrypt-data and --encrypt-data simultaneously has no effect"); queue_init_message("Warning: Using --unencrypt-data and --encrypt-data simultaneously has no effect");
} }
/* Make sure all written files are read/writeable only by the current user. */
umask(S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
init_default_data_files(); init_default_data_files();
bool datafile_exists = file_exists(DATA_FILE); bool datafile_exists = file_exists(DATA_FILE);

View File

@ -89,6 +89,7 @@ struct arg_opts {
bool no_connect; bool no_connect;
bool encrypt_data; bool encrypt_data;
bool unencrypt_data; bool unencrypt_data;
bool logging;
char nameserver_path[MAX_STR_SIZE]; char nameserver_path[MAX_STR_SIZE];
char config_path[MAX_STR_SIZE]; char config_path[MAX_STR_SIZE];