summaryrefslogtreecommitdiffstats
path: root/tools/idevicesyslog.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/idevicesyslog.c')
-rw-r--r--tools/idevicesyslog.c54
1 files changed, 40 insertions, 14 deletions
diff --git a/tools/idevicesyslog.c b/tools/idevicesyslog.c
index 3084b97..a0e641d 100644
--- a/tools/idevicesyslog.c
+++ b/tools/idevicesyslog.c
@@ -149,7 +149,7 @@ static void syslog_callback(char c, void *user_data)
do {
if (lp < 16) {
shall_print = 1;
- cprintf(COLOR_WHITE);
+ cprintf(FG_WHITE);
break;
}
@@ -282,35 +282,35 @@ static void syslog_callback(char c, void *user_data)
const char* level_color = NULL;
if (!strncmp(p, "<Notice>:", 9)) {
level_end += 9;
- level_color = COLOR_GREEN;
+ level_color = FG_GREEN;
} else if (!strncmp(p, "<Error>:", 8)) {
level_end += 8;
- level_color = COLOR_RED;
+ level_color = FG_RED;
} else if (!strncmp(p, "<Warning>:", 10)) {
level_end += 10;
- level_color = COLOR_YELLOW;
+ level_color = FG_YELLOW;
} else if (!strncmp(p, "<Debug>:", 8)) {
level_end += 8;
- level_color = COLOR_MAGENTA;
+ level_color = FG_MAGENTA;
} else {
- level_color = COLOR_WHITE;
+ level_color = FG_WHITE;
}
/* write date and time */
- cprintf(COLOR_LIGHT_GRAY);
+ cprintf(FG_LIGHT_GRAY);
fwrite(line, 1, 16, stdout);
if (show_device_name) {
/* write device name */
- cprintf(COLOR_DARK_YELLOW);
+ cprintf(FG_DARK_YELLOW);
fwrite(device_name_start, 1, device_name_end-device_name_start+1, stdout);
cprintf(COLOR_RESET);
}
/* write process name */
- cprintf(COLOR_BRIGHT_CYAN);
+ cprintf(FG_BRIGHT_CYAN);
fwrite(process_name_start, 1, process_name_end-process_name_start, stdout);
- cprintf(COLOR_CYAN);
+ cprintf(FG_CYAN);
fwrite(process_name_end, 1, proc_name_end-process_name_end+1, stdout);
/* write log level */
@@ -323,11 +323,11 @@ static void syslog_callback(char c, void *user_data)
lp -= p - linep;
linep = p;
- cprintf(COLOR_WHITE);
+ cprintf(FG_WHITE);
} else {
shall_print = 1;
- cprintf(COLOR_WHITE);
+ cprintf(FG_WHITE);
}
} while (0);
@@ -480,7 +480,10 @@ static void print_usage(int argc, char **argv, int is_error)
" -h, --help prints usage information\n"
" -d, --debug enable communication debugging\n"
" -v, --version prints version information\n"
- " --no-colors disable colored output\n"
+ " --no-colors disable colored output\n"
+ " -o, --output FILE write to FILE instead of stdout\n"
+ " (existing FILE will be overwritten)\n"
+ " --colors force writing colored output, e.g. for --output\n"
"\n"
"FILTER OPTIONS:\n"
" -m, --match STRING only print messages that contain STRING\n"
@@ -508,6 +511,7 @@ int main(int argc, char *argv[])
int exclude_filter = 0;
int include_kernel = 0;
int exclude_kernel = 0;
+ int force_colors = 0;
int c = 0;
const struct option longopts[] = {
{ "debug", no_argument, NULL, 'd' },
@@ -525,6 +529,8 @@ int main(int argc, char *argv[])
{ "no-kernel", no_argument, NULL, 'K' },
{ "quiet-list", no_argument, NULL, 1 },
{ "no-colors", no_argument, NULL, 2 },
+ { "colors", no_argument, NULL, 3 },
+ { "output", required_argument, NULL, 'o' },
{ "version", no_argument, NULL, 'v' },
{ NULL, 0, NULL, 0}
};
@@ -536,7 +542,7 @@ int main(int argc, char *argv[])
signal(SIGPIPE, SIG_IGN);
#endif
- while ((c = getopt_long(argc, argv, "dhu:nxt:T:m:e:p:qkKv", longopts, NULL)) != -1) {
+ while ((c = getopt_long(argc, argv, "dhu:nxt:T:m:e:p:qkKo:v", longopts, NULL)) != -1) {
switch (c) {
case 'd':
idevice_set_debug_level(1);
@@ -638,6 +644,22 @@ int main(int argc, char *argv[])
case 2:
term_colors_set_enabled(0);
break;
+ case 3:
+ force_colors = 1;
+ break;
+ case 'o':
+ if (!*optarg) {
+ fprintf(stderr, "ERROR: --output option requires an argument!\n");
+ print_usage(argc, argv, 1);
+ return 2;
+ } else {
+ if (freopen(optarg, "w", stdout) == NULL) {
+ fprintf(stderr, "ERROR: Failed to open output file '%s' for writing: %s\n", optarg, strerror(errno));
+ return 1;
+ }
+ term_colors_set_enabled(0);
+ }
+ break;
case 'v':
printf("%s %s\n", TOOL_NAME, PACKAGE_VERSION);
return 0;
@@ -647,6 +669,10 @@ int main(int argc, char *argv[])
}
}
+ if (force_colors) {
+ term_colors_set_enabled(1);
+ }
+
if (include_kernel > 0 && exclude_kernel > 0) {
fprintf(stderr, "ERROR: -k and -K cannot be used together.\n");
print_usage(argc, argv, 1);