brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 1 | #include <stdio.h> |
| 2 | #include <stdlib.h> |
Daniel Petti | aa5bdb1 | 2014-12-20 16:33:05 -0800 | [diff] [blame] | 3 | #include <string.h> |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 4 | #include <getopt.h> |
| 5 | #include <sys/types.h> |
| 6 | #include <sys/stat.h> |
| 7 | #include <fcntl.h> |
| 8 | #include <inttypes.h> |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 9 | |
Brian Silverman | 88471dc | 2014-02-15 22:35:42 -0800 | [diff] [blame] | 10 | #include <algorithm> |
Daniel Petti | b6c885b | 2014-09-12 10:04:28 -0700 | [diff] [blame] | 11 | #include <memory> |
| 12 | #include <string> |
Brian Silverman | 88471dc | 2014-02-15 22:35:42 -0800 | [diff] [blame] | 13 | |
John Park | 398c74a | 2018-10-20 21:17:39 -0700 | [diff] [blame] | 14 | #include "aos/configuration.h" |
John Park | 33858a3 | 2018-09-28 23:05:48 -0700 | [diff] [blame] | 15 | #include "aos/logging/binary_log_file.h" |
John Park | 33858a3 | 2018-09-28 23:05:48 -0700 | [diff] [blame] | 16 | #include "aos/logging/logging.h" |
| 17 | #include "aos/logging/implementations.h" |
| 18 | #include "aos/logging/printf_formats.h" |
| 19 | #include "aos/util/string_to_num.h" |
Brian Silverman | 88471dc | 2014-02-15 22:35:42 -0800 | [diff] [blame] | 20 | |
| 21 | using ::aos::logging::linux_code::LogFileMessageHeader; |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 22 | |
| 23 | namespace { |
| 24 | |
| 25 | const char *kArgsHelp = "[OPTION]... [FILE]\n" |
| 26 | "Display log file FILE (created by BinaryLogReader) to stdout.\n" |
| 27 | "FILE is \"aos_log-current\" by default.\n" |
Brian Silverman | 65e569d | 2014-10-24 15:43:20 -0400 | [diff] [blame] | 28 | "FILE can also be \"-\" to read from standard input.\n" |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 29 | "\n" |
Brian Silverman | 8c2b00e | 2015-02-17 20:30:50 -0500 | [diff] [blame] | 30 | " -n, --name-prefix NAME " |
| 31 | "only display entries from processes which share NAME as a prefix\n" |
| 32 | " -N, --name NAME only display entries from processes named NAME\n" |
| 33 | " -l, --level LEVEL " |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 34 | "only display log entries at least as important as LEVEL\n" |
Brian Silverman | 8c2b00e | 2015-02-17 20:30:50 -0500 | [diff] [blame] | 35 | " -p, --pid PID only display log entries from process PID\n" |
| 36 | " -f, --follow " |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 37 | "wait when the end of the file is reached (implies --end)\n" |
Brian Silverman | 8c2b00e | 2015-02-17 20:30:50 -0500 | [diff] [blame] | 38 | " -t, --terminate stop when the end of file is reached (default)\n" |
| 39 | " -b, --beginning start at the beginning of the file (default)\n" |
| 40 | " -e, --end start at the end of the file\n" |
| 41 | " -s, --skip NUMBER skip NUMBER matching logs\n" |
| 42 | " -m, --max NUMBER only display up to NUMBER logs\n" |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 43 | " // -o, --format FORMAT use FORMAT to display log entries\n" |
Brian Silverman | 8c2b00e | 2015-02-17 20:30:50 -0500 | [diff] [blame] | 44 | " -h, --help display this help and exit\n" |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 45 | "\n" |
| 46 | "LEVEL must be DEBUG, INFO, WARNING, ERROR, or FATAL.\n" |
| 47 | " It defaults to INFO.\n" |
| 48 | "\n" |
Daniel Petti | e6f33e2 | 2014-08-21 20:35:55 -0700 | [diff] [blame] | 49 | "TODO(brians) implement the commented out ones.\n"; |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 50 | |
Daniel Petti | 88c81f4 | 2014-09-12 10:05:05 -0700 | [diff] [blame] | 51 | const char *kExampleUsages = "To view logs from the shooter:\n" |
| 52 | "\t`log_displayer -n shooter`\n" |
| 53 | "To view debug logs from the shooter:\n" |
| 54 | "\t`log_displayer -n shooter -l DEBUG`\n" |
| 55 | "To view what the shooter is logging in realtime:\n" |
| 56 | "\t`log_displayer -f -n shooter`\n" |
| 57 | "To view shooter logs from an old log file:\n" |
| 58 | "\t`log_displayer aos_log-<number> -n shooter`\n" |
| 59 | "To view the statuses of the shooter hall effects in realtime:\n" |
| 60 | "\t`log_displayer -f -n shooter -l DEBUG | grep .Position`\n"; |
| 61 | |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 62 | void PrintHelpAndExit() { |
| 63 | fprintf(stderr, "Usage: %s %s", program_invocation_name, kArgsHelp); |
Daniel Petti | 88c81f4 | 2014-09-12 10:05:05 -0700 | [diff] [blame] | 64 | fprintf(stderr, "\nExample usages:\n\n%s", kExampleUsages); |
| 65 | |
| 66 | // Get the possible executables from start_list.txt. |
| 67 | FILE *start_list = fopen("start_list.txt", "r"); |
Daniel Petti | aa5bdb1 | 2014-12-20 16:33:05 -0800 | [diff] [blame] | 68 | if (!start_list) { |
| 69 | ::std::string path(::aos::configuration::GetRootDirectory()); |
| 70 | path += "/start_list.txt"; |
| 71 | start_list = fopen(path.c_str(), "r"); |
| 72 | if (!start_list) { |
| 73 | printf("\nCannot open start_list.txt. This means that the\n" |
| 74 | "possible arguments for the -n option cannot be shown. log_displayer\n" |
| 75 | "looks for start_list.txt in the current working directory and in\n" |
| 76 | "%s.\n\n", ::aos::configuration::GetRootDirectory()); |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame] | 77 | AOS_PLOG(FATAL, "Unable to open start_list.txt"); |
Daniel Petti | aa5bdb1 | 2014-12-20 16:33:05 -0800 | [diff] [blame] | 78 | } |
Daniel Petti | 88c81f4 | 2014-09-12 10:05:05 -0700 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | // Get file size. |
| 82 | if (fseek(start_list, 0, SEEK_END)) { |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame] | 83 | AOS_PLOG(FATAL, "fseek() failed while reading start_list.txt"); |
Daniel Petti | 88c81f4 | 2014-09-12 10:05:05 -0700 | [diff] [blame] | 84 | } |
| 85 | int size = ftell(start_list); |
| 86 | if (size < 0) { |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame] | 87 | AOS_PLOG(FATAL, "ftell() failed while reading start_list.txt"); |
Daniel Petti | 88c81f4 | 2014-09-12 10:05:05 -0700 | [diff] [blame] | 88 | } |
| 89 | rewind(start_list); |
| 90 | |
| 91 | ::std::unique_ptr<char[]> contents(new char[size + 1]); |
| 92 | if (contents == NULL) { |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame] | 93 | AOS_LOG(FATAL, "malloc() failed while reading start_list.txt.\n"); |
Daniel Petti | 88c81f4 | 2014-09-12 10:05:05 -0700 | [diff] [blame] | 94 | } |
| 95 | size_t bytes_read = fread(contents.get(), 1, size, start_list); |
| 96 | if (bytes_read < static_cast<size_t>(size)) { |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame] | 97 | AOS_LOG(FATAL, "Read %zu bytes from start_list.txt, expected %d.\n", |
| 98 | bytes_read, size); |
Daniel Petti | 88c81f4 | 2014-09-12 10:05:05 -0700 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | // printf doesn't like strings without the \0. |
| 102 | contents[size] = '\0'; |
| 103 | fprintf(stderr, "\nPossible arguments for the -n option:\n%s", contents.get()); |
| 104 | |
| 105 | if (fclose(start_list)) { |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame] | 106 | AOS_LOG(FATAL, "fclose() failed.\n"); |
Daniel Petti | 88c81f4 | 2014-09-12 10:05:05 -0700 | [diff] [blame] | 107 | } |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 108 | |
| 109 | exit(EXIT_SUCCESS); |
| 110 | } |
| 111 | |
| 112 | } // namespace |
| 113 | |
| 114 | int main(int argc, char **argv) { |
Brian Silverman | 8c2b00e | 2015-02-17 20:30:50 -0500 | [diff] [blame] | 115 | const char *filter_name = nullptr, *filter_exact_name = nullptr; |
Brian Silverman | f778031 | 2014-02-16 17:26:15 -0800 | [diff] [blame] | 116 | size_t filter_length = 0; |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 117 | log_level filter_level = INFO; |
Brian Silverman | f778031 | 2014-02-16 17:26:15 -0800 | [diff] [blame] | 118 | bool follow = false; |
| 119 | // Whether we need to skip everything until we get to the end of the file. |
| 120 | bool skip_to_end = false; |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 121 | const char *filename = "aos_log-current"; |
Daniel Petti | b6c885b | 2014-09-12 10:04:28 -0700 | [diff] [blame] | 122 | int display_max = 0; |
| 123 | int32_t source_pid = -1; |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 124 | |
Brian Silverman | ff48578 | 2014-06-18 19:59:09 -0700 | [diff] [blame] | 125 | ::aos::logging::Init(); |
Brian Silverman | f778031 | 2014-02-16 17:26:15 -0800 | [diff] [blame] | 126 | ::aos::logging::AddImplementation( |
| 127 | new ::aos::logging::StreamLogImplementation(stdout)); |
| 128 | |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 129 | while (true) { |
| 130 | static struct option long_options[] = { |
Brian Silverman | 8c2b00e | 2015-02-17 20:30:50 -0500 | [diff] [blame] | 131 | {"name-prefix", required_argument, NULL, 'n'}, |
| 132 | {"name", required_argument, NULL, 'N'}, |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 133 | {"level", required_argument, NULL, 'l'}, |
| 134 | {"pid", required_argument, NULL, 'p'}, |
| 135 | |
| 136 | {"follow", no_argument, NULL, 'f'}, |
| 137 | {"terminate", no_argument, NULL, 't'}, |
| 138 | {"beginning", no_argument, NULL, 'b'}, |
| 139 | {"end", no_argument, NULL, 'e'}, |
| 140 | {"skip", required_argument, NULL, 's'}, |
| 141 | {"max", required_argument, NULL, 'm'}, |
| 142 | |
| 143 | {"format", required_argument, NULL, 'o'}, |
| 144 | |
| 145 | {"help", no_argument, NULL, 'h'}, |
| 146 | {0, 0, 0, 0} |
| 147 | }; |
| 148 | int option_index = 0; |
| 149 | |
Brian Silverman | dbcc87d | 2015-03-15 20:41:34 -0700 | [diff] [blame] | 150 | const int c = getopt_long(argc, argv, "N:n:l:p:fts:m:o:h", |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 151 | long_options, &option_index); |
| 152 | if (c == -1) { // if we're at the end |
| 153 | break; |
| 154 | } |
| 155 | switch (c) { |
| 156 | case 0: |
Daniel Petti | 88c81f4 | 2014-09-12 10:05:05 -0700 | [diff] [blame] | 157 | fputs("LogDisplayer: got a 0 option but didn't set up any\n", stderr); |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 158 | abort(); |
| 159 | case 'n': |
| 160 | filter_name = optarg; |
Brian Silverman | 8c2b00e | 2015-02-17 20:30:50 -0500 | [diff] [blame] | 161 | filter_exact_name = nullptr; |
| 162 | filter_length = strlen(filter_name); |
| 163 | break; |
| 164 | case 'N': |
| 165 | filter_exact_name = optarg; |
| 166 | filter_name = nullptr; |
Brian Silverman | 88471dc | 2014-02-15 22:35:42 -0800 | [diff] [blame] | 167 | filter_length = strlen(filter_name); |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 168 | break; |
| 169 | case 'l': |
Brian Silverman | ab6615c | 2013-03-05 20:29:29 -0800 | [diff] [blame] | 170 | filter_level = ::aos::logging::str_log(optarg); |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 171 | if (filter_level == LOG_UNKNOWN) { |
| 172 | fprintf(stderr, "LogDisplayer: unknown log level '%s'\n", optarg); |
| 173 | exit(EXIT_FAILURE); |
| 174 | } |
| 175 | break; |
| 176 | case 'p': |
Daniel Petti | 5aa2979 | 2014-12-27 17:48:07 -0500 | [diff] [blame] | 177 | if (!::aos::util::StringToNumber(::std::string(optarg), &source_pid)) { |
Daniel Petti | b6c885b | 2014-09-12 10:04:28 -0700 | [diff] [blame] | 178 | fprintf(stderr, "ERROR: -p expects a number, not '%s'.\n", optarg); |
| 179 | exit(EXIT_FAILURE); |
| 180 | } |
| 181 | if (source_pid < 0) { |
| 182 | fprintf(stderr, "LogDisplayer: invalid pid '%s'\n", optarg); |
| 183 | exit(EXIT_FAILURE); |
| 184 | } |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 185 | break; |
| 186 | case 'f': |
| 187 | follow = true; |
Brian Silverman | f778031 | 2014-02-16 17:26:15 -0800 | [diff] [blame] | 188 | skip_to_end = true; |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 189 | break; |
| 190 | case 't': |
| 191 | follow = false; |
| 192 | break; |
| 193 | case 'b': |
Brian Silverman | f778031 | 2014-02-16 17:26:15 -0800 | [diff] [blame] | 194 | skip_to_end = false; |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 195 | break; |
| 196 | case 'e': |
Brian Silverman | f778031 | 2014-02-16 17:26:15 -0800 | [diff] [blame] | 197 | skip_to_end = true; |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 198 | break; |
| 199 | case 'm': |
Daniel Petti | 5aa2979 | 2014-12-27 17:48:07 -0500 | [diff] [blame] | 200 | if (!::aos::util::StringToNumber(::std::string(optarg), &display_max)) { |
Daniel Petti | b6c885b | 2014-09-12 10:04:28 -0700 | [diff] [blame] | 201 | fprintf(stderr, "ERROR: -m expects a number, not '%s'.\n", optarg); |
| 202 | exit(EXIT_FAILURE); |
| 203 | } |
| 204 | if (display_max <= 0) { |
| 205 | fprintf(stderr, "LogDisplayer: invalid max log number '%s'\n", |
| 206 | optarg); |
| 207 | exit(EXIT_FAILURE); |
| 208 | } |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 209 | break; |
| 210 | case 'o': |
| 211 | abort(); |
| 212 | break; |
| 213 | case 'h': |
| 214 | PrintHelpAndExit(); |
| 215 | break; |
| 216 | case '?': |
| 217 | break; |
| 218 | default: |
Brian Silverman | ab6615c | 2013-03-05 20:29:29 -0800 | [diff] [blame] | 219 | fprintf(stderr, "LogDisplayer: in a bad spot (%s: %d)\n", |
| 220 | __FILE__, __LINE__); |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 221 | abort(); |
| 222 | } |
| 223 | } |
| 224 | |
Daniel Petti | e6f33e2 | 2014-08-21 20:35:55 -0700 | [diff] [blame] | 225 | if (optind < argc) { |
| 226 | // We got a filename. |
| 227 | filename = argv[optind++]; |
| 228 | } |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 229 | if (optind < argc) { |
Daniel Petti | 88c81f4 | 2014-09-12 10:05:05 -0700 | [diff] [blame] | 230 | fputs("non-option ARGV-elements: ", stderr); |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 231 | while (optind < argc) { |
| 232 | fprintf(stderr, "%s\n", argv[optind++]); |
| 233 | } |
| 234 | } |
| 235 | |
Brian Silverman | 65e569d | 2014-10-24 15:43:20 -0400 | [diff] [blame] | 236 | int fd; |
| 237 | if (strcmp(filename, "-") == 0) { |
Brian Silverman | f5ca4d0 | 2015-03-01 16:52:24 -0500 | [diff] [blame] | 238 | if (skip_to_end) { |
| 239 | fputs("Can't skip to end of stdin!\n", stderr); |
| 240 | return EXIT_FAILURE; |
| 241 | } |
Brian Silverman | 65e569d | 2014-10-24 15:43:20 -0400 | [diff] [blame] | 242 | fd = STDIN_FILENO; |
| 243 | } else { |
| 244 | fd = open(filename, O_RDONLY); |
| 245 | } |
Daniel Petti | e6f33e2 | 2014-08-21 20:35:55 -0700 | [diff] [blame] | 246 | |
Brian Silverman | f5ca4d0 | 2015-03-01 16:52:24 -0500 | [diff] [blame] | 247 | fprintf(stderr, "displaying down to level %s from file '%s'\n", |
| 248 | ::aos::logging::log_str(filter_level), filename); |
| 249 | |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 250 | if (fd == -1) { |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame] | 251 | AOS_PLOG(FATAL, "couldn't open file '%s' for reading", filename); |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 252 | } |
Brian Silverman | ab5ba47 | 2014-04-18 15:26:14 -0700 | [diff] [blame] | 253 | ::aos::logging::linux_code::LogFileReader reader(fd); |
Brian Silverman | f778031 | 2014-02-16 17:26:15 -0800 | [diff] [blame] | 254 | |
| 255 | if (skip_to_end) { |
| 256 | fputs("skipping old logs...\n", stderr); |
Brian Silverman | f5ca4d0 | 2015-03-01 16:52:24 -0500 | [diff] [blame] | 257 | reader.SkipToLastSeekablePage(); |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 258 | } |
Brian Silverman | 88471dc | 2014-02-15 22:35:42 -0800 | [diff] [blame] | 259 | |
| 260 | const LogFileMessageHeader *msg; |
Daniel Petti | b6c885b | 2014-09-12 10:04:28 -0700 | [diff] [blame] | 261 | int displayed = 0; |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 262 | do { |
Brian Silverman | ab5ba47 | 2014-04-18 15:26:14 -0700 | [diff] [blame] | 263 | msg = reader.ReadNextMessage(follow); |
Brian Silverman | 003ba4b | 2014-02-10 16:56:18 -0800 | [diff] [blame] | 264 | if (msg == NULL) { |
| 265 | fputs("reached end of file\n", stderr); |
| 266 | return 0; |
| 267 | } |
Brian Silverman | 88471dc | 2014-02-15 22:35:42 -0800 | [diff] [blame] | 268 | |
Brian Silverman | 64833d4 | 2015-02-08 21:11:36 -0500 | [diff] [blame] | 269 | if (source_pid >= 0 && msg->source != source_pid) { |
| 270 | // Message is from the wrong process. |
| 271 | continue; |
| 272 | } |
| 273 | |
Brian Silverman | f778031 | 2014-02-16 17:26:15 -0800 | [diff] [blame] | 274 | if (skip_to_end) { |
Brian Silverman | ab5ba47 | 2014-04-18 15:26:14 -0700 | [diff] [blame] | 275 | if (reader.IsLastPage()) { |
Brian Silverman | f778031 | 2014-02-16 17:26:15 -0800 | [diff] [blame] | 276 | fputs("done skipping old logs\n", stderr); |
| 277 | skip_to_end = false; |
| 278 | } else { |
| 279 | continue; |
| 280 | } |
| 281 | } |
| 282 | |
Brian Silverman | 88471dc | 2014-02-15 22:35:42 -0800 | [diff] [blame] | 283 | if (::aos::logging::log_gt_important(filter_level, msg->level)) continue; |
Brian Silverman | 8c2b00e | 2015-02-17 20:30:50 -0500 | [diff] [blame] | 284 | |
Brian Silverman | 58657aa | 2015-02-21 20:06:40 -0500 | [diff] [blame] | 285 | const char *position = |
| 286 | reinterpret_cast<const char *>(msg + 1); |
| 287 | |
Brian Silverman | 8c2b00e | 2015-02-17 20:30:50 -0500 | [diff] [blame] | 288 | if (filter_name != nullptr) { |
| 289 | const size_t compare_length = |
| 290 | ::std::min<size_t>(filter_length, msg->name_size); |
Brian Silverman | 58657aa | 2015-02-21 20:06:40 -0500 | [diff] [blame] | 291 | if (memcmp(filter_name, position, compare_length) != 0) { |
Brian Silverman | 8c2b00e | 2015-02-17 20:30:50 -0500 | [diff] [blame] | 292 | continue; |
| 293 | } |
Brian Silverman | 58657aa | 2015-02-21 20:06:40 -0500 | [diff] [blame] | 294 | if (compare_length < msg->name_size) { |
| 295 | if (position[compare_length] != '.') continue; |
| 296 | } |
Brian Silverman | 8c2b00e | 2015-02-17 20:30:50 -0500 | [diff] [blame] | 297 | } |
| 298 | |
| 299 | if (filter_exact_name != nullptr) { |
| 300 | if (filter_length != msg->name_size) continue; |
Brian Silverman | 58657aa | 2015-02-21 20:06:40 -0500 | [diff] [blame] | 301 | if (memcmp(filter_exact_name, position, filter_length) != 0) { |
Brian Silverman | 88471dc | 2014-02-15 22:35:42 -0800 | [diff] [blame] | 302 | continue; |
| 303 | } |
| 304 | } |
| 305 | |
Daniel Petti | b6c885b | 2014-09-12 10:04:28 -0700 | [diff] [blame] | 306 | if (display_max && displayed++ >= display_max) { |
| 307 | fputs("Not displaying the rest of the messages.\n", stderr); |
| 308 | return 0; |
| 309 | } |
| 310 | |
Brian Silverman | 58657aa | 2015-02-21 20:06:40 -0500 | [diff] [blame] | 311 | position += msg->name_size; |
| 312 | |
Brian Silverman | a7234c6 | 2014-03-24 20:23:25 -0700 | [diff] [blame] | 313 | #define BASE_ARGS \ |
| 314 | AOS_LOGGING_BASE_ARGS( \ |
| 315 | msg->name_size, reinterpret_cast<const char *>(msg + 1), msg->source, \ |
| 316 | msg->sequence, msg->level, msg->time_sec, msg->time_nsec) |
Brian Silverman | 88471dc | 2014-02-15 22:35:42 -0800 | [diff] [blame] | 317 | switch (msg->type) { |
Brian Silverman | a7234c6 | 2014-03-24 20:23:25 -0700 | [diff] [blame] | 318 | case LogFileMessageHeader::MessageType::kString: |
| 319 | fprintf(stdout, AOS_LOGGING_BASE_FORMAT "%.*s", BASE_ARGS, |
| 320 | static_cast<int>(msg->message_size), position); |
Brian Silverman | 88471dc | 2014-02-15 22:35:42 -0800 | [diff] [blame] | 321 | break; |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 322 | case LogFileMessageHeader::MessageType::kStruct: |
| 323 | case LogFileMessageHeader::MessageType::kMatrix: |
| 324 | AOS_LOG(FATAL, "Unsupported matrix or struct\n"); |
| 325 | break; |
Brian Silverman | 88471dc | 2014-02-15 22:35:42 -0800 | [diff] [blame] | 326 | case LogFileMessageHeader::MessageType::kStructType: |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame] | 327 | AOS_LOG(FATAL, "shouldn't get here\n"); |
Brian Silverman | 88471dc | 2014-02-15 22:35:42 -0800 | [diff] [blame] | 328 | break; |
Brian Silverman | a7234c6 | 2014-03-24 20:23:25 -0700 | [diff] [blame] | 329 | } |
| 330 | #undef BASE_ARGS |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 331 | } while (msg != NULL); |
| 332 | } |