Added log level param

This commit is contained in:
Vysheng 2013-11-15 20:14:25 +04:00
parent bbe5222651
commit 78f3e7aa31
3 changed files with 88 additions and 43 deletions

View File

@ -50,6 +50,8 @@ int msg_num_mode;
int in_readline;
int readline_active;
int log_level;
long long cur_uploading_bytes;
long long cur_uploaded_bytes;
long long cur_downloading_bytes;
@ -278,6 +280,7 @@ char *commands[] = {
"status_offline",
"contacts_search",
"quit",
"set",
0 };
int commands_flags[] = {
@ -315,6 +318,7 @@ int commands_flags[] = {
07,
07,
07,
07,
};
int get_complete_mode (void) {
@ -769,6 +773,13 @@ void interpreter (char *line UU) {
"rename_contact <user> <first-name> <last-name> - tries to rename contact. If you have another device it will be a fight\n"
"suggested_contacts - print info about contacts, you have max common friends\n"
"visualize_key <secret_chat> - prints visualization of encryption key. You should compare it to your partner's one\n"
"set <param> <param-value>. Possible <param> values are:\n"
"\tdebug_verbosity - just as it sounds. Debug verbosity\n"
"\tlog_level - level of logging of new events. Lower is less verbose:\n"
"\t\tLevel 1: prints info about read messages\n"
"\t\tLevel 2: prints line, when somebody is typing in chat\n"
"\t\tLevel 3: prints line, when somebody changes online status\n"
"\tmsg_num - enables/disables numeration of messages\n"
);
pop_color ();
} else if (IS_WORD ("show_license")) {
@ -822,6 +833,20 @@ void interpreter (char *line UU) {
RET;
}
do_contacts_search (100, s);
} else if (IS_WORD ("set")) {
command = next_token (&l);
long long num = next_token_int ();
if (num == NOT_FOUND) {
printf ("Bad msg id\n");
RET;
}
if (IS_WORD ("debug_verbosity")) {
verbosity = num;
} else if (IS_WORD ("log_level")) {
log_level = num;
} else if (IS_WORD ("msg_num")) {
msg_num_mode = num;
}
} else if (IS_WORD ("quit")) {
exit (0);
}

13
main.c
View File

@ -76,6 +76,7 @@ char *downloads_directory;
char *config_directory;
char *binlog_file_name;
int binlog_enabled;
extern int log_level;
void set_default_username (const char *s) {
if (default_username) {
@ -260,6 +261,9 @@ void parse_config (void) {
strcpy (buf + l, "test");
config_lookup_bool (&conf, buf, &test_dc);
strcpy (buf + l, "log_level");
config_lookup_int (&conf, buf, &log_level);
if (!msg_num_mode) {
strcpy (buf + l, "msg_num");
config_lookup_bool (&conf, buf, &msg_num_mode);
@ -300,7 +304,7 @@ void inner_main (void) {
}
void usage (void) {
printf ("%s [-u username] [-h] [-k public key name] [-N] [-v]\n", PROGNAME);
printf ("%s [-u username] [-h] [-k public key name] [-N] [-v] [-l log_level]\n", PROGNAME);
exit (1);
}
@ -310,7 +314,7 @@ extern int default_dc_num;
void args_parse (int argc, char **argv) {
int opt = 0;
while ((opt = getopt (argc, argv, "u:hk:vn:Nc:p:")) != -1) {
while ((opt = getopt (argc, argv, "u:hk:vn:Nc:p:l:")) != -1) {
switch (opt) {
case 'u':
set_default_username (optarg);
@ -331,6 +335,9 @@ void args_parse (int argc, char **argv) {
prefix = strdup (optarg);
assert (strlen (prefix) <= 100);
break;
case 'l':
log_level = atoi (optarg);
break;
case 'h':
default:
usage ();
@ -356,6 +363,8 @@ void sig_handler (int signum) {
int main (int argc, char **argv) {
signal (SIGSEGV, sig_handler);
signal (SIGABRT, sig_handler);
log_level = 10;
args_parse (argc, argv);
printf (

View File

@ -51,6 +51,7 @@
#include "mtproto-common.h"
#define MAX_NET_RES (1L << 16)
extern int log_level;
int verbosity;
int auth_success;
@ -739,26 +740,30 @@ void work_update (struct connection *c UU, long long msg_id UU) {
}
}
fetch_pts ();
print_start ();
push_color (COLOR_YELLOW);
print_date (time (0));
printf (" %d messages marked as read\n", n);
pop_color ();
print_end ();
if (log_level >= 1) {
print_start ();
push_color (COLOR_YELLOW);
print_date (time (0));
printf (" %d messages marked as read\n", n);
pop_color ();
print_end ();
}
}
break;
case CODE_update_user_typing:
{
peer_id_t id = MK_USER (fetch_int ());
peer_t *U = user_chat_get (id);
print_start ();
push_color (COLOR_YELLOW);
print_date (time (0));
printf (" User ");
print_user_name (id, U);
printf (" is typing....\n");
pop_color ();
print_end ();
if (log_level >= 2) {
print_start ();
push_color (COLOR_YELLOW);
print_date (time (0));
printf (" User ");
print_user_name (id, U);
printf (" is typing....\n");
pop_color ();
print_end ();
}
}
break;
case CODE_update_chat_user_typing:
@ -767,16 +772,18 @@ void work_update (struct connection *c UU, long long msg_id UU) {
peer_id_t id = MK_USER (fetch_int ());
peer_t *C = user_chat_get (chat_id);
peer_t *U = user_chat_get (id);
print_start ();
push_color (COLOR_YELLOW);
print_date (time (0));
printf (" User ");
print_user_name (id, U);
printf (" is typing in chat ");
print_chat_name (chat_id, C);
printf ("....\n");
pop_color ();
print_end ();
if (log_level >= 2) {
print_start ();
push_color (COLOR_YELLOW);
print_date (time (0));
printf (" User ");
print_user_name (id, U);
printf (" is typing in chat ");
print_chat_name (chat_id, C);
printf ("....\n");
pop_color ();
print_end ();
}
}
break;
case CODE_update_user_status:
@ -785,15 +792,17 @@ void work_update (struct connection *c UU, long long msg_id UU) {
peer_t *U = user_chat_get (user_id);
if (U) {
fetch_user_status (&U->user.status);
print_start ();
push_color (COLOR_YELLOW);
print_date (time (0));
printf (" User ");
print_user_name (user_id, U);
printf (" is now ");
printf ("%s\n", (U->user.status.online > 0) ? "online" : "offline");
pop_color ();
print_end ();
if (log_level >= 3) {
print_start ();
push_color (COLOR_YELLOW);
print_date (time (0));
printf (" User ");
print_user_name (user_id, U);
printf (" is now ");
printf ("%s\n", (U->user.status.online > 0) ? "online" : "offline");
pop_color ();
print_end ();
}
} else {
struct user_status t;
fetch_user_status (&t);
@ -1097,14 +1106,16 @@ void work_update (struct connection *c UU, long long msg_id UU) {
M = M->next;
}
}
print_start ();
push_color (COLOR_YELLOW);
print_date (time (0));
printf (" Encrypted chat ");
print_encr_chat_name_full (id, user_chat_get (id));
printf (": %d messages marked read \n", x);
pop_color ();
print_end ();
if (log_level >= 1) {
print_start ();
push_color (COLOR_YELLOW);
print_date (time (0));
printf (" Encrypted chat ");
print_encr_chat_name_full (id, user_chat_get (id));
printf (": %d messages marked read \n", x);
pop_color ();
print_end ();
}
}
break;
case CODE_update_chat_participant_add: