blob: 51d1a3afa301416f69d3840ae877fe1d35126dcd [file] [log] [blame]
Mark Salyzyn7b30ff82015-01-26 13:41:33 -08001// Copyright 2006-2015 The Android Open Source Project
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08002
Mark Salyzyn3ef730c2015-06-02 07:57:16 -07003#include <arpa/inet.h>
Mark Salyzyn65772ca2013-12-13 11:10:11 -08004#include <assert.h>
5#include <ctype.h>
Mark Salyzynf3555d92015-05-27 07:39:56 -07006#include <dirent.h>
Mark Salyzyn65772ca2013-12-13 11:10:11 -08007#include <errno.h>
8#include <fcntl.h>
Kristian Monsen562e5132015-06-05 14:10:12 -07009#include <getopt.h>
Aristidis Papaioannoueba73442014-10-16 22:19:55 -070010#include <math.h>
Mark Salyzyn3ef730c2015-06-02 07:57:16 -070011#include <sched.h>
12#include <signal.h>
13#include <stdarg.h>
Mark Salyzyn65772ca2013-12-13 11:10:11 -080014#include <stdio.h>
15#include <stdlib.h>
Mark Salyzyn65772ca2013-12-13 11:10:11 -080016#include <string.h>
Traian Schiau59763032015-04-10 15:51:39 +030017#include <sys/cdefs.h>
Riley Andrewsaede9892015-06-08 23:36:34 -070018#include <sys/resource.h>
Mark Salyzyn65772ca2013-12-13 11:10:11 -080019#include <sys/socket.h>
20#include <sys/stat.h>
Mark Salyzynf3555d92015-05-27 07:39:56 -070021#include <sys/types.h>
Mark Salyzyn3ef730c2015-06-02 07:57:16 -070022#include <time.h>
23#include <unistd.h>
Mark Salyzyn65772ca2013-12-13 11:10:11 -080024
Mark Salyzynf3555d92015-05-27 07:39:56 -070025#include <memory>
26#include <string>
27
Elliott Hughes4f713192015-12-04 22:00:26 -080028#include <android-base/file.h>
Mark Salyzyn5b1a5382016-08-03 14:20:41 -070029#include <android-base/stringprintf.h>
Elliott Hughes4f713192015-12-04 22:00:26 -080030#include <android-base/strings.h>
Mark Salyzyn3ef730c2015-06-02 07:57:16 -070031#include <cutils/sched_policy.h>
Mark Salyzyn65772ca2013-12-13 11:10:11 -080032#include <cutils/sockets.h>
Mark Salyzyn3ef730c2015-06-02 07:57:16 -070033#include <log/event_tag_map.h>
Colin Cross9227bd32013-07-23 16:59:20 -070034#include <log/logprint.h>
Mark Salyzynaeaaf812016-09-30 13:30:33 -070035#include <private/android_logger.h>
Elliott Hughesb9e53b42016-02-17 11:58:01 -080036#include <system/thread_defs.h>
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080037
Casey Dahlindc42a872016-03-17 16:18:55 -070038#include <pcrecpp.h>
39
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080040#define DEFAULT_MAX_ROTATED_LOGS 4
41
42static AndroidLogFormat * g_logformat;
43
44/* logd prefixes records with a length field */
45#define RECORD_LENGTH_FIELD_SIZE_BYTES sizeof(uint32_t)
46
Joe Onorato6fa09a02010-02-26 10:04:23 -080047struct log_device_t {
Mark Salyzyn95132e92013-11-22 10:55:48 -080048 const char* device;
Joe Onorato6fa09a02010-02-26 10:04:23 -080049 bool binary;
Mark Salyzyn95132e92013-11-22 10:55:48 -080050 struct logger *logger;
51 struct logger_list *logger_list;
Joe Onorato6fa09a02010-02-26 10:04:23 -080052 bool printed;
Joe Onorato6fa09a02010-02-26 10:04:23 -080053
Joe Onorato6fa09a02010-02-26 10:04:23 -080054 log_device_t* next;
55
Mark Salyzyn5f6738a2015-02-27 13:41:34 -080056 log_device_t(const char* d, bool b) {
Joe Onorato6fa09a02010-02-26 10:04:23 -080057 device = d;
58 binary = b;
Joe Onorato6fa09a02010-02-26 10:04:23 -080059 next = NULL;
60 printed = false;
Traian Schiau59763032015-04-10 15:51:39 +030061 logger = NULL;
62 logger_list = NULL;
Joe Onorato6fa09a02010-02-26 10:04:23 -080063 }
Joe Onorato6fa09a02010-02-26 10:04:23 -080064};
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080065
66namespace android {
67
68/* Global Variables */
69
Mark Salyzync6d66522016-03-30 12:38:29 -070070static const char * g_outputFileName;
Traian Schiau59763032015-04-10 15:51:39 +030071// 0 means "no log rotation"
Mark Salyzync6d66522016-03-30 12:38:29 -070072static size_t g_logRotateSizeKBytes;
Traian Schiau59763032015-04-10 15:51:39 +030073// 0 means "unbounded"
74static size_t g_maxRotatedLogs = DEFAULT_MAX_ROTATED_LOGS;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080075static int g_outFD = -1;
Mark Salyzync6d66522016-03-30 12:38:29 -070076static size_t g_outByteCount;
77static int g_printBinary;
78static int g_devCount; // >1 means multiple
Casey Dahlindc42a872016-03-17 16:18:55 -070079static pcrecpp::RE* g_regex;
Casey Dahlin6ac498d2016-03-17 14:04:52 -070080// 0 means "infinite"
Mark Salyzync6d66522016-03-30 12:38:29 -070081static size_t g_maxCount;
82static size_t g_printCount;
Mark Salyzync9202772016-03-30 09:38:31 -070083static bool g_printItAnyways;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080084
Mark Salyzynaa730c12016-03-30 12:38:29 -070085// if showHelp is set, newline required in fmt statement to transition to usage
Traian Schiau59763032015-04-10 15:51:39 +030086__noreturn static void logcat_panic(bool showHelp, const char *fmt, ...) __printflike(2,3);
87
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080088static int openLogFile (const char *pathname)
89{
Edwin Vane80b221c2012-08-13 12:55:07 -040090 return open(pathname, O_WRONLY | O_APPEND | O_CREAT, S_IRUSR | S_IWUSR);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080091}
92
93static void rotateLogs()
94{
95 int err;
96
97 // Can't rotate logs if we're not outputting to a file
98 if (g_outputFileName == NULL) {
99 return;
100 }
101
102 close(g_outFD);
103
Aristidis Papaioannoueba73442014-10-16 22:19:55 -0700104 // Compute the maximum number of digits needed to count up to g_maxRotatedLogs in decimal.
105 // eg: g_maxRotatedLogs == 30 -> log10(30) == 1.477 -> maxRotationCountDigits == 2
106 int maxRotationCountDigits =
107 (g_maxRotatedLogs > 0) ? (int) (floor(log10(g_maxRotatedLogs) + 1)) : 0;
108
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800109 for (int i = g_maxRotatedLogs ; i > 0 ; i--) {
Mark Salyzyn5b1a5382016-08-03 14:20:41 -0700110 std::string file1 = android::base::StringPrintf(
111 "%s.%.*d", g_outputFileName, maxRotationCountDigits, i);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800112
Mark Salyzyn5b1a5382016-08-03 14:20:41 -0700113 std::string file0;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800114 if (i - 1 == 0) {
Mark Salyzyn5b1a5382016-08-03 14:20:41 -0700115 file0 = android::base::StringPrintf("%s", g_outputFileName);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800116 } else {
Mark Salyzyn5b1a5382016-08-03 14:20:41 -0700117 file0 = android::base::StringPrintf(
118 "%s.%.*d", g_outputFileName, maxRotationCountDigits, i - 1);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800119 }
120
Mark Salyzyn5b1a5382016-08-03 14:20:41 -0700121 if ((file0.length() == 0) || (file1.length() == 0)) {
Traian Schiau59763032015-04-10 15:51:39 +0300122 perror("while rotating log files");
123 break;
124 }
125
Mark Salyzyn5b1a5382016-08-03 14:20:41 -0700126 err = rename(file0.c_str(), file1.c_str());
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800127
128 if (err < 0 && errno != ENOENT) {
129 perror("while rotating log files");
130 }
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800131 }
132
Traian Schiau59763032015-04-10 15:51:39 +0300133 g_outFD = openLogFile(g_outputFileName);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800134
135 if (g_outFD < 0) {
Traian Schiau59763032015-04-10 15:51:39 +0300136 logcat_panic(false, "couldn't open output file");
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800137 }
138
139 g_outByteCount = 0;
140
141}
142
Mark Salyzyn95132e92013-11-22 10:55:48 -0800143void printBinary(struct log_msg *buf)
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800144{
Mark Salyzyn95132e92013-11-22 10:55:48 -0800145 size_t size = buf->len();
146
147 TEMP_FAILURE_RETRY(write(g_outFD, buf, size));
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800148}
149
Mark Salyzynaa730c12016-03-30 12:38:29 -0700150static bool regexOk(const AndroidLogEntry& entry)
Casey Dahlindc42a872016-03-17 16:18:55 -0700151{
Mark Salyzynaa730c12016-03-30 12:38:29 -0700152 if (!g_regex) {
Casey Dahlindc42a872016-03-17 16:18:55 -0700153 return true;
154 }
155
Casey Dahlindc42a872016-03-17 16:18:55 -0700156 std::string messageString(entry.message, entry.messageLen);
157
158 return g_regex->PartialMatch(messageString);
159}
160
Mark Salyzyn95132e92013-11-22 10:55:48 -0800161static void processBuffer(log_device_t* dev, struct log_msg *buf)
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800162{
Mathias Agopian50844522010-03-17 16:10:26 -0700163 int bytesWritten = 0;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800164 int err;
165 AndroidLogEntry entry;
166 char binaryMsgBuf[1024];
167
Joe Onorato6fa09a02010-02-26 10:04:23 -0800168 if (dev->binary) {
Mark Salyzyn9421b0c2015-02-26 14:33:35 -0800169 static bool hasOpenedEventTagMap = false;
170 static EventTagMap *eventTagMap = NULL;
171
172 if (!eventTagMap && !hasOpenedEventTagMap) {
173 eventTagMap = android_openEventTagMap(EVENT_TAG_MAP_FILE);
174 hasOpenedEventTagMap = true;
175 }
Mark Salyzyn95132e92013-11-22 10:55:48 -0800176 err = android_log_processBinaryLogBuffer(&buf->entry_v1, &entry,
Mark Salyzyn9421b0c2015-02-26 14:33:35 -0800177 eventTagMap,
Mark Salyzyn95132e92013-11-22 10:55:48 -0800178 binaryMsgBuf,
179 sizeof(binaryMsgBuf));
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800180 //printf(">>> pri=%d len=%d msg='%s'\n",
181 // entry.priority, entry.messageLen, entry.message);
182 } else {
Mark Salyzyn95132e92013-11-22 10:55:48 -0800183 err = android_log_processLogBuffer(&buf->entry_v1, &entry);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800184 }
Joe Onoratoe2bf2ea2010-03-01 09:11:54 -0800185 if (err < 0) {
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800186 goto error;
Joe Onoratoe2bf2ea2010-03-01 09:11:54 -0800187 }
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800188
Mark Salyzync9202772016-03-30 09:38:31 -0700189 if (android_log_shouldPrintLine(g_logformat, entry.tag, entry.priority)) {
190 bool match = regexOk(entry);
Joe Onoratoe2bf2ea2010-03-01 09:11:54 -0800191
Mark Salyzync9202772016-03-30 09:38:31 -0700192 g_printCount += match;
193 if (match || g_printItAnyways) {
194 bytesWritten = android_log_printLogLine(g_logformat, g_outFD, &entry);
Casey Dahlin6ac498d2016-03-17 14:04:52 -0700195
Mark Salyzync9202772016-03-30 09:38:31 -0700196 if (bytesWritten < 0) {
197 logcat_panic(false, "output error");
198 }
Joe Onoratoe2bf2ea2010-03-01 09:11:54 -0800199 }
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800200 }
201
202 g_outByteCount += bytesWritten;
203
Mark Salyzyn95132e92013-11-22 10:55:48 -0800204 if (g_logRotateSizeKBytes > 0
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800205 && (g_outByteCount / 1024) >= g_logRotateSizeKBytes
206 ) {
207 rotateLogs();
208 }
209
210error:
211 //fprintf (stderr, "Error processing record\n");
212 return;
213}
214
Mark Salyzyn7b30ff82015-01-26 13:41:33 -0800215static void maybePrintStart(log_device_t* dev, bool printDividers) {
216 if (!dev->printed || printDividers) {
Dan Egnord1d3b6d2010-03-11 20:32:17 -0800217 if (g_devCount > 1 && !g_printBinary) {
218 char buf[1024];
Mark Salyzyn7b30ff82015-01-26 13:41:33 -0800219 snprintf(buf, sizeof(buf), "--------- %s %s\n",
220 dev->printed ? "switch to" : "beginning of",
Mark Salyzyn95132e92013-11-22 10:55:48 -0800221 dev->device);
Dan Egnord1d3b6d2010-03-11 20:32:17 -0800222 if (write(g_outFD, buf, strlen(buf)) < 0) {
Traian Schiau59763032015-04-10 15:51:39 +0300223 logcat_panic(false, "output error");
Joe Onorato6fa09a02010-02-26 10:04:23 -0800224 }
225 }
Mark Salyzyn7b30ff82015-01-26 13:41:33 -0800226 dev->printed = true;
Joe Onorato6fa09a02010-02-26 10:04:23 -0800227 }
228}
229
Mark Salyzynad5e4112016-08-04 07:53:52 -0700230static void setupOutputAndSchedulingPolicy(bool blocking) {
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800231 if (g_outputFileName == NULL) {
232 g_outFD = STDOUT_FILENO;
Mark Salyzynad5e4112016-08-04 07:53:52 -0700233 return;
234 }
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800235
Mark Salyzynad5e4112016-08-04 07:53:52 -0700236 if (blocking) {
237 // Lower priority and set to batch scheduling if we are saving
238 // the logs into files and taking continuous content.
Mark Salyzyn3ef730c2015-06-02 07:57:16 -0700239 if (set_sched_policy(0, SP_BACKGROUND) < 0) {
240 fprintf(stderr, "failed to set background scheduling policy\n");
241 }
242
243 struct sched_param param;
244 memset(&param, 0, sizeof(param));
245 if (sched_setscheduler((pid_t) 0, SCHED_BATCH, &param) < 0) {
246 fprintf(stderr, "failed to set to batch scheduler\n");
247 }
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800248
Riley Andrewsaede9892015-06-08 23:36:34 -0700249 if (setpriority(PRIO_PROCESS, 0, ANDROID_PRIORITY_BACKGROUND) < 0) {
250 fprintf(stderr, "failed set to priority\n");
251 }
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800252 }
Mark Salyzynad5e4112016-08-04 07:53:52 -0700253
254 g_outFD = openLogFile (g_outputFileName);
255
256 if (g_outFD < 0) {
257 logcat_panic(false, "couldn't open output file");
258 }
259
260 struct stat statbuf;
261 if (fstat(g_outFD, &statbuf) == -1) {
262 close(g_outFD);
263 logcat_panic(false, "couldn't get output file stat\n");
264 }
265
266 if ((size_t) statbuf.st_size > SIZE_MAX || statbuf.st_size < 0) {
267 close(g_outFD);
268 logcat_panic(false, "invalid output file stat\n");
269 }
270
271 g_outByteCount = statbuf.st_size;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800272}
273
274static void show_help(const char *cmd)
275{
276 fprintf(stderr,"Usage: %s [options] [filterspecs]\n", cmd);
277
278 fprintf(stderr, "options include:\n"
Mark Salyzyn378f4742016-04-12 09:11:46 -0700279 " -s Set default filter to silent. Equivalent to filterspec '*:S'\n"
280 " -f <file>, --file=<file> Log to file. Default is stdout\n"
Mark Salyzyn1325ebf2016-06-07 13:03:10 -0700281 " -r <kbytes>, --rotate-kbytes=<kbytes>\n"
282 " Rotate log every kbytes. Requires -f option\n"
283 " -n <count>, --rotate-count=<count>\n"
284 " Sets max number of rotated logs to <count>, default 4\n"
Mark Salyzyn02687e72016-08-03 14:20:41 -0700285 " --id=<id> If the signature id for logging to file changes, then clear\n"
286 " the fileset and continue\n"
Mark Salyzyn378f4742016-04-12 09:11:46 -0700287 " -v <format>, --format=<format>\n"
Mark Salyzyn9cfd1c62016-07-06 11:12:14 -0700288 " Sets log print format verb and adverbs, where <format> is:\n"
Mark Salyzyne735a732016-07-06 13:30:40 -0700289 " brief long process raw tag thread threadtime time\n"
290 " and individually flagged modifying adverbs can be added:\n"
Mark Salyzyn9cfd1c62016-07-06 11:12:14 -0700291 " color epoch monotonic printable uid usec UTC year zone\n"
Mark Salyzyn378f4742016-04-12 09:11:46 -0700292 " -D, --dividers Print dividers between each log buffer\n"
293 " -c, --clear Clear (flush) the entire log and exit\n"
Mark Salyzynb7d059b2016-06-06 14:56:00 -0700294 " if Log to File specified, clear fileset instead\n"
Mark Salyzyn378f4742016-04-12 09:11:46 -0700295 " -d Dump the log and then exit (don't block)\n"
296 " -e <expr>, --regex=<expr>\n"
297 " Only print lines where the log message matches <expr>\n"
298 " where <expr> is a regular expression\n"
299 // Leave --head undocumented as alias for -m
300 " -m <count>, --max-count=<count>\n"
301 " Quit after printing <count> lines. This is meant to be\n"
302 " paired with --regex, but will work on its own.\n"
303 " --print Paired with --regex and --max-count to let content bypass\n"
Mark Salyzync9202772016-03-30 09:38:31 -0700304 " regex filter but still stop at number of matches.\n"
Mark Salyzyn378f4742016-04-12 09:11:46 -0700305 // Leave --tail undocumented as alias for -t
306 " -t <count> Print only the most recent <count> lines (implies -d)\n"
307 " -t '<time>' Print most recent lines since specified time (implies -d)\n"
308 " -T <count> Print only the most recent <count> lines (does not imply -d)\n"
309 " -T '<time>' Print most recent lines since specified time (not imply -d)\n"
Mark Salyzynf28f6a92015-08-31 08:01:33 -0700310 " count is pure numerical, time is 'MM-DD hh:mm:ss.mmm...'\n"
Mark Salyzyn4cbed022015-08-31 15:53:41 -0700311 " 'YYYY-MM-DD hh:mm:ss.mmm...' or 'sssss.mmm...' format\n"
Mark Salyzyn378f4742016-04-12 09:11:46 -0700312 " -g, --buffer-size Get the size of the ring buffer.\n"
313 " -G <size>, --buffer-size=<size>\n"
314 " Set size of log ring buffer, may suffix with K or M.\n"
315 " -L, -last Dump logs from prior to last reboot\n"
Mark Salyzyn083b0372015-12-04 10:59:45 -0800316 // Leave security (Device Owner only installations) and
317 // kernel (userdebug and eng) buffers undocumented.
Mark Salyzyn378f4742016-04-12 09:11:46 -0700318 " -b <buffer>, --buffer=<buffer> Request alternate ring buffer, 'main',\n"
319 " 'system', 'radio', 'events', 'crash', 'default' or 'all'.\n"
Mark Salyzyn45177732016-04-11 14:03:48 -0700320 " Multiple -b parameters or comma separated list of buffers are\n"
321 " allowed. Buffers interleaved. Default -b main,system,crash.\n"
Mark Salyzyn378f4742016-04-12 09:11:46 -0700322 " -B, --binary Output the log in binary.\n"
323 " -S, --statistics Output statistics.\n"
324 " -p, --prune Print prune white and ~black list. Service is specified as\n"
325 " UID, UID/PID or /PID. Weighed for quicker pruning if prefix\n"
Mark Salyzynbbbe14f2014-04-11 13:49:43 -0700326 " with ~, otherwise weighed for longevity if unadorned. All\n"
327 " other pruning activity is oldest first. Special case ~!\n"
328 " represents an automatic quicker pruning for the noisiest\n"
329 " UID as determined by the current statistics.\n"
Mark Salyzyn378f4742016-04-12 09:11:46 -0700330 " -P '<list> ...', --prune='<list> ...'\n"
331 " Set prune white and ~black list, using same format as\n"
332 " listed above. Must be quoted.\n"
Mark Salyzyn41ba25f2015-11-30 13:48:56 -0800333 " --pid=<pid> Only prints logs from the given pid.\n"
Mark Salyzyn378f4742016-04-12 09:11:46 -0700334 // Check ANDROID_LOG_WRAP_DEFAULT_TIMEOUT value for match to 2 hours
Mark Salyzyn41ba25f2015-11-30 13:48:56 -0800335 " --wrap Sleep for 2 hours or when buffer about to wrap whichever\n"
336 " comes first. Improves efficiency of polling by providing\n"
337 " an about-to-wrap wakeup.\n");
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800338
Mark Salyzyn1325ebf2016-06-07 13:03:10 -0700339 fprintf(stderr,"\nfilterspecs are a series of \n"
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800340 " <tag>[:priority]\n\n"
341 "where <tag> is a log component tag (or * for all) and priority is:\n"
Mark Salyzynbba894a2015-03-09 09:32:56 -0700342 " V Verbose (default for <tag>)\n"
343 " D Debug (default for '*')\n"
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800344 " I Info\n"
345 " W Warn\n"
346 " E Error\n"
347 " F Fatal\n"
Mark Salyzynbba894a2015-03-09 09:32:56 -0700348 " S Silent (suppress all output)\n"
349 "\n'*' by itself means '*:D' and <tag> by itself means <tag>:V.\n"
350 "If no '*' filterspec or -s on command line, all filter defaults to '*:V'.\n"
351 "eg: '*:S <tag>' prints only <tag>, '<tag>:S' suppresses all <tag> log messages.\n"
352 "\nIf not specified on the command line, filterspec is set from ANDROID_LOG_TAGS.\n"
353 "\nIf not specified with -v on command line, format is set from ANDROID_PRINTF_LOG\n"
Mark Salyzyn649fc602014-09-16 09:15:15 -0700354 "or defaults to \"threadtime\"\n\n");
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800355}
356
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800357static int setLogFormat(const char * formatString)
358{
359 static AndroidLogPrintFormat format;
360
361 format = android_log_formatFromString(formatString);
362
363 if (format == FORMAT_OFF) {
364 // FORMAT_OFF means invalid string
365 return -1;
366 }
367
Mark Salyzyne1f20042015-05-06 08:40:40 -0700368 return android_log_setPrintFormat(g_logformat, format);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800369}
370
Mark Salyzyn671e3432014-05-06 07:34:59 -0700371static const char multipliers[][2] = {
372 { "" },
373 { "K" },
374 { "M" },
375 { "G" }
376};
377
378static unsigned long value_of_size(unsigned long value)
379{
380 for (unsigned i = 0;
381 (i < sizeof(multipliers)/sizeof(multipliers[0])) && (value >= 1024);
382 value /= 1024, ++i) ;
383 return value;
384}
385
386static const char *multiplier_of_size(unsigned long value)
387{
388 unsigned i;
389 for (i = 0;
390 (i < sizeof(multipliers)/sizeof(multipliers[0])) && (value >= 1024);
391 value /= 1024, ++i) ;
392 return multipliers[i];
393}
394
Traian Schiau59763032015-04-10 15:51:39 +0300395/*String to unsigned int, returns -1 if it fails*/
Mark Salyzyn33c26252016-04-12 09:11:46 -0700396static bool getSizeTArg(const char *ptr, size_t *val, size_t min = 0,
Traian Schiau59763032015-04-10 15:51:39 +0300397 size_t max = SIZE_MAX)
398{
Kristian Monsen562e5132015-06-05 14:10:12 -0700399 if (!ptr) {
Traian Schiau59763032015-04-10 15:51:39 +0300400 return false;
401 }
402
Kristian Monsen562e5132015-06-05 14:10:12 -0700403 char *endp;
404 errno = 0;
405 size_t ret = (size_t)strtoll(ptr, &endp, 0);
406
407 if (endp[0] || errno) {
408 return false;
409 }
410
411 if ((ret > max) || (ret < min)) {
Traian Schiau59763032015-04-10 15:51:39 +0300412 return false;
413 }
414
415 *val = ret;
416 return true;
417}
418
419static void logcat_panic(bool showHelp, const char *fmt, ...)
420{
Mark Salyzyn77d7e812015-04-13 09:27:57 -0700421 va_list args;
422 va_start(args, fmt);
423 vfprintf(stderr, fmt, args);
424 va_end(args);
Traian Schiau59763032015-04-10 15:51:39 +0300425
426 if (showHelp) {
427 show_help(getprogname());
428 }
429
430 exit(EXIT_FAILURE);
431}
432
Mark Salyzynf28f6a92015-08-31 08:01:33 -0700433static char *parseTime(log_time &t, const char *cp) {
434
435 char *ep = t.strptime(cp, "%m-%d %H:%M:%S.%q");
436 if (ep) {
437 return ep;
438 }
Mark Salyzyn4cbed022015-08-31 15:53:41 -0700439 ep = t.strptime(cp, "%Y-%m-%d %H:%M:%S.%q");
440 if (ep) {
441 return ep;
442 }
443 return t.strptime(cp, "%s.%q");
Mark Salyzynf28f6a92015-08-31 08:01:33 -0700444}
Mark Salyzynf3555d92015-05-27 07:39:56 -0700445
Mark Salyzyn31961062016-08-04 07:43:46 -0700446// Find last logged line in <outputFileName>, or <outputFileName>.1
Mark Salyzynf3555d92015-05-27 07:39:56 -0700447static log_time lastLogTime(char *outputFileName) {
448 log_time retval(log_time::EPOCH);
449 if (!outputFileName) {
450 return retval;
451 }
452
Mark Salyzynf3555d92015-05-27 07:39:56 -0700453 std::string directory;
454 char *file = strrchr(outputFileName, '/');
455 if (!file) {
456 directory = ".";
457 file = outputFileName;
458 } else {
459 *file = '\0';
460 directory = outputFileName;
461 *file = '/';
462 ++file;
463 }
Mark Salyzync18c2132016-04-01 07:52:20 -0700464
465 std::unique_ptr<DIR, int(*)(DIR*)>
466 dir(opendir(directory.c_str()), closedir);
467 if (!dir.get()) {
468 return retval;
469 }
470
Mark Salyzyn31961062016-08-04 07:43:46 -0700471 log_time now(android_log_clockid());
Mark Salyzync18c2132016-04-01 07:52:20 -0700472
Mark Salyzynf3555d92015-05-27 07:39:56 -0700473 size_t len = strlen(file);
474 log_time modulo(0, NS_PER_SEC);
Mark Salyzynf3555d92015-05-27 07:39:56 -0700475 struct dirent *dp;
Mark Salyzync18c2132016-04-01 07:52:20 -0700476
Mark Salyzynf3555d92015-05-27 07:39:56 -0700477 while ((dp = readdir(dir.get())) != NULL) {
Mark Salyzyn31961062016-08-04 07:43:46 -0700478 if ((dp->d_type != DT_REG) ||
479 (strncmp(dp->d_name, file, len) != 0) ||
480 (dp->d_name[len] &&
481 ((dp->d_name[len] != '.') ||
482 (strtoll(dp->d_name + 1, NULL, 10) != 1)))) {
Mark Salyzynf3555d92015-05-27 07:39:56 -0700483 continue;
484 }
485
486 std::string file_name = directory;
487 file_name += "/";
488 file_name += dp->d_name;
489 std::string file;
490 if (!android::base::ReadFileToString(file_name, &file)) {
491 continue;
492 }
493
494 bool found = false;
495 for (const auto& line : android::base::Split(file, "\n")) {
496 log_time t(log_time::EPOCH);
Mark Salyzynf28f6a92015-08-31 08:01:33 -0700497 char *ep = parseTime(t, line.c_str());
Mark Salyzynf3555d92015-05-27 07:39:56 -0700498 if (!ep || (*ep != ' ')) {
499 continue;
500 }
501 // determine the time precision of the logs (eg: msec or usec)
502 for (unsigned long mod = 1UL; mod < modulo.tv_nsec; mod *= 10) {
503 if (t.tv_nsec % (mod * 10)) {
504 modulo.tv_nsec = mod;
505 break;
506 }
507 }
508 // We filter any times later than current as we may not have the
509 // year stored with each log entry. Also, since it is possible for
510 // entries to be recorded out of order (very rare) we select the
511 // maximum we find just in case.
512 if ((t < now) && (t > retval)) {
513 retval = t;
514 found = true;
515 }
516 }
517 // We count on the basename file to be the definitive end, so stop here.
518 if (!dp->d_name[len] && found) {
519 break;
520 }
521 }
522 if (retval == log_time::EPOCH) {
523 return retval;
524 }
525 // tail_time prints matching or higher, round up by the modulo to prevent
526 // a replay of the last entry we have just checked.
527 retval += modulo;
528 return retval;
529}
530
Traian Schiau59763032015-04-10 15:51:39 +0300531} /* namespace android */
532
533
Joe Onorato6fa09a02010-02-26 10:04:23 -0800534int main(int argc, char **argv)
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800535{
Traian Schiau59763032015-04-10 15:51:39 +0300536 using namespace android;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800537 int err;
538 int hasSetLogFormat = 0;
539 int clearLog = 0;
540 int getLogSize = 0;
Mark Salyzyndfa7a072014-02-11 12:29:31 -0800541 unsigned long setLogSize = 0;
542 int getPruneList = 0;
543 char *setPruneList = NULL;
Mark Salyzyn02687e72016-08-03 14:20:41 -0700544 char *setId = NULL;
Mark Salyzyn34facab2014-02-06 14:48:50 -0800545 int printStatistics = 0;
Mark Salyzyn2d3f38a2015-01-26 10:46:44 -0800546 int mode = ANDROID_LOG_RDONLY;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800547 const char *forceFilters = NULL;
Joe Onorato6fa09a02010-02-26 10:04:23 -0800548 log_device_t* devices = NULL;
549 log_device_t* dev;
Mark Salyzyn7b30ff82015-01-26 13:41:33 -0800550 bool printDividers = false;
Mark Salyzyn95132e92013-11-22 10:55:48 -0800551 struct logger_list *logger_list;
Traian Schiau59763032015-04-10 15:51:39 +0300552 size_t tail_lines = 0;
Mark Salyzynfa3716b2014-02-14 16:05:05 -0800553 log_time tail_time(log_time::EPOCH);
Kristian Monsen562e5132015-06-05 14:10:12 -0700554 size_t pid = 0;
Casey Dahlin6ac498d2016-03-17 14:04:52 -0700555 bool got_t = false;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800556
Mark Salyzyn65772ca2013-12-13 11:10:11 -0800557 signal(SIGPIPE, exit);
558
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800559 g_logformat = android_log_format_new();
560
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800561 if (argc == 2 && 0 == strcmp(argv[1], "--help")) {
Traian Schiau59763032015-04-10 15:51:39 +0300562 show_help(argv[0]);
563 return EXIT_SUCCESS;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800564 }
565
566 for (;;) {
567 int ret;
568
Kristian Monsen562e5132015-06-05 14:10:12 -0700569 int option_index = 0;
Mark Salyzync9202772016-03-30 09:38:31 -0700570 // list of long-argument only strings for later comparison
Kristian Monsen562e5132015-06-05 14:10:12 -0700571 static const char pid_str[] = "pid";
Mark Salyzyn02687e72016-08-03 14:20:41 -0700572 static const char id_str[] = "id";
Mark Salyzyn41ba25f2015-11-30 13:48:56 -0800573 static const char wrap_str[] = "wrap";
Mark Salyzync9202772016-03-30 09:38:31 -0700574 static const char print_str[] = "print";
Kristian Monsen562e5132015-06-05 14:10:12 -0700575 static const struct option long_options[] = {
Mark Salyzynf8bff872015-11-30 12:57:56 -0800576 { "binary", no_argument, NULL, 'B' },
577 { "buffer", required_argument, NULL, 'b' },
Mark Salyzynd85f6462016-03-30 09:15:09 -0700578 { "buffer-size", optional_argument, NULL, 'g' },
Mark Salyzynf8bff872015-11-30 12:57:56 -0800579 { "clear", no_argument, NULL, 'c' },
580 { "dividers", no_argument, NULL, 'D' },
581 { "file", required_argument, NULL, 'f' },
582 { "format", required_argument, NULL, 'v' },
Mark Salyzync18c2132016-04-01 07:52:20 -0700583 // hidden and undocumented reserved alias for --regex
584 { "grep", required_argument, NULL, 'e' },
Mark Salyzynd85f6462016-03-30 09:15:09 -0700585 // hidden and undocumented reserved alias for --max-count
586 { "head", required_argument, NULL, 'm' },
Mark Salyzyn02687e72016-08-03 14:20:41 -0700587 { id_str, required_argument, NULL, 0 },
Mark Salyzynf8bff872015-11-30 12:57:56 -0800588 { "last", no_argument, NULL, 'L' },
Casey Dahlin6ac498d2016-03-17 14:04:52 -0700589 { "max-count", required_argument, NULL, 'm' },
Mark Salyzync18c2132016-04-01 07:52:20 -0700590 { pid_str, required_argument, NULL, 0 },
Mark Salyzync9202772016-03-30 09:38:31 -0700591 { print_str, no_argument, NULL, 0 },
Mark Salyzynf8bff872015-11-30 12:57:56 -0800592 { "prune", optional_argument, NULL, 'p' },
Casey Dahlindc42a872016-03-17 16:18:55 -0700593 { "regex", required_argument, NULL, 'e' },
Mark Salyzynd85f6462016-03-30 09:15:09 -0700594 { "rotate-count", required_argument, NULL, 'n' },
595 { "rotate-kbytes", required_argument, NULL, 'r' },
Mark Salyzynf8bff872015-11-30 12:57:56 -0800596 { "statistics", no_argument, NULL, 'S' },
Mark Salyzynd85f6462016-03-30 09:15:09 -0700597 // hidden and undocumented reserved alias for -t
598 { "tail", required_argument, NULL, 't' },
Mark Salyzyn41ba25f2015-11-30 13:48:56 -0800599 // support, but ignore and do not document, the optional argument
600 { wrap_str, optional_argument, NULL, 0 },
Kristian Monsen562e5132015-06-05 14:10:12 -0700601 { NULL, 0, NULL, 0 }
602 };
603
Casey Dahlin6ac498d2016-03-17 14:04:52 -0700604 ret = getopt_long(argc, argv, ":cdDLt:T:gG:sQf:r:n:v:b:BSpP:m:e:",
Kristian Monsen562e5132015-06-05 14:10:12 -0700605 long_options, &option_index);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800606
607 if (ret < 0) {
608 break;
609 }
610
Kristian Monsen562e5132015-06-05 14:10:12 -0700611 switch (ret) {
612 case 0:
Mark Salyzyn02687e72016-08-03 14:20:41 -0700613 // only long options
Kristian Monsen562e5132015-06-05 14:10:12 -0700614 if (long_options[option_index].name == pid_str) {
615 // ToDo: determine runtime PID_MAX?
616 if (!getSizeTArg(optarg, &pid, 1)) {
617 logcat_panic(true, "%s %s out of range\n",
618 long_options[option_index].name, optarg);
619 }
620 break;
621 }
Mark Salyzyn41ba25f2015-11-30 13:48:56 -0800622 if (long_options[option_index].name == wrap_str) {
623 mode |= ANDROID_LOG_WRAP |
624 ANDROID_LOG_RDONLY |
625 ANDROID_LOG_NONBLOCK;
626 // ToDo: implement API that supports setting a wrap timeout
627 size_t dummy = ANDROID_LOG_WRAP_DEFAULT_TIMEOUT;
628 if (optarg && !getSizeTArg(optarg, &dummy, 1)) {
629 logcat_panic(true, "%s %s out of range\n",
630 long_options[option_index].name, optarg);
631 }
632 if (dummy != ANDROID_LOG_WRAP_DEFAULT_TIMEOUT) {
633 fprintf(stderr,
634 "WARNING: %s %u seconds, ignoring %zu\n",
635 long_options[option_index].name,
636 ANDROID_LOG_WRAP_DEFAULT_TIMEOUT, dummy);
637 }
638 break;
639 }
Mark Salyzync9202772016-03-30 09:38:31 -0700640 if (long_options[option_index].name == print_str) {
641 g_printItAnyways = true;
642 break;
643 }
Mark Salyzyn02687e72016-08-03 14:20:41 -0700644 if (long_options[option_index].name == id_str) {
645 setId = optarg && optarg[0] ? optarg : NULL;
646 break;
647 }
Kristian Monsen562e5132015-06-05 14:10:12 -0700648 break;
649
Mark Salyzyn95132e92013-11-22 10:55:48 -0800650 case 's':
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800651 // default to all silent
652 android_log_addFilterRule(g_logformat, "*:s");
653 break;
654
655 case 'c':
656 clearLog = 1;
Mark Salyzyn2d3f38a2015-01-26 10:46:44 -0800657 mode |= ANDROID_LOG_WRONLY;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800658 break;
659
Mark Salyzyn7c975ac2014-12-15 10:01:31 -0800660 case 'L':
Mark Salyzynad5e4112016-08-04 07:53:52 -0700661 mode |= ANDROID_LOG_RDONLY | ANDROID_LOG_PSTORE | ANDROID_LOG_NONBLOCK;
Mark Salyzyn7c975ac2014-12-15 10:01:31 -0800662 break;
663
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800664 case 'd':
Mark Salyzyn2d3f38a2015-01-26 10:46:44 -0800665 mode |= ANDROID_LOG_RDONLY | ANDROID_LOG_NONBLOCK;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800666 break;
667
Dan Egnord1d3b6d2010-03-11 20:32:17 -0800668 case 't':
Casey Dahlin6ac498d2016-03-17 14:04:52 -0700669 got_t = true;
Mark Salyzyn2d3f38a2015-01-26 10:46:44 -0800670 mode |= ANDROID_LOG_RDONLY | ANDROID_LOG_NONBLOCK;
Mark Salyzyn5d3d1f12013-12-09 13:47:00 -0800671 /* FALLTHRU */
672 case 'T':
Mark Salyzynfa3716b2014-02-14 16:05:05 -0800673 if (strspn(optarg, "0123456789") != strlen(optarg)) {
Mark Salyzynf28f6a92015-08-31 08:01:33 -0700674 char *cp = parseTime(tail_time, optarg);
Mark Salyzynfa3716b2014-02-14 16:05:05 -0800675 if (!cp) {
Mark Salyzynf28f6a92015-08-31 08:01:33 -0700676 logcat_panic(false, "-%c \"%s\" not in time format\n",
677 ret, optarg);
Mark Salyzynfa3716b2014-02-14 16:05:05 -0800678 }
679 if (*cp) {
680 char c = *cp;
681 *cp = '\0';
682 fprintf(stderr,
683 "WARNING: -%c \"%s\"\"%c%s\" time truncated\n",
684 ret, optarg, c, cp + 1);
685 *cp = c;
686 }
687 } else {
Traian Schiau59763032015-04-10 15:51:39 +0300688 if (!getSizeTArg(optarg, &tail_lines, 1)) {
Mark Salyzynfa3716b2014-02-14 16:05:05 -0800689 fprintf(stderr,
690 "WARNING: -%c %s invalid, setting to 1\n",
691 ret, optarg);
692 tail_lines = 1;
693 }
694 }
Dan Egnord1d3b6d2010-03-11 20:32:17 -0800695 break;
696
Mark Salyzyn7b30ff82015-01-26 13:41:33 -0800697 case 'D':
698 printDividers = true;
699 break;
700
Casey Dahlindc42a872016-03-17 16:18:55 -0700701 case 'e':
702 g_regex = new pcrecpp::RE(optarg);
703 break;
704
Casey Dahlin6ac498d2016-03-17 14:04:52 -0700705 case 'm': {
706 char *end = NULL;
707 if (!getSizeTArg(optarg, &g_maxCount)) {
708 logcat_panic(false, "-%c \"%s\" isn't an "
709 "integer greater than zero\n", ret, optarg);
710 }
711 }
712 break;
713
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800714 case 'g':
Mark Salyzynf8bff872015-11-30 12:57:56 -0800715 if (!optarg) {
716 getLogSize = 1;
717 break;
718 }
719 // FALLTHRU
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800720
Mark Salyzyndfa7a072014-02-11 12:29:31 -0800721 case 'G': {
Traian Schiau59763032015-04-10 15:51:39 +0300722 char *cp;
723 if (strtoll(optarg, &cp, 0) > 0) {
724 setLogSize = strtoll(optarg, &cp, 0);
725 } else {
726 setLogSize = 0;
Mark Salyzyndfa7a072014-02-11 12:29:31 -0800727 }
728
729 switch(*cp) {
730 case 'g':
731 case 'G':
732 setLogSize *= 1024;
733 /* FALLTHRU */
734 case 'm':
735 case 'M':
736 setLogSize *= 1024;
737 /* FALLTHRU */
738 case 'k':
739 case 'K':
740 setLogSize *= 1024;
741 /* FALLTHRU */
742 case '\0':
743 break;
744
745 default:
746 setLogSize = 0;
747 }
748
749 if (!setLogSize) {
750 fprintf(stderr, "ERROR: -G <num><multiplier>\n");
Traian Schiau59763032015-04-10 15:51:39 +0300751 return EXIT_FAILURE;
Mark Salyzyndfa7a072014-02-11 12:29:31 -0800752 }
753 }
754 break;
755
756 case 'p':
Mark Salyzynf8bff872015-11-30 12:57:56 -0800757 if (!optarg) {
758 getPruneList = 1;
759 break;
760 }
761 // FALLTHRU
Mark Salyzyndfa7a072014-02-11 12:29:31 -0800762
763 case 'P':
764 setPruneList = optarg;
765 break;
766
Joe Onorato6fa09a02010-02-26 10:04:23 -0800767 case 'b': {
Mark Salyzyn45177732016-04-11 14:03:48 -0700768 unsigned idMask = 0;
Mark Salyzyn1325ebf2016-06-07 13:03:10 -0700769 while ((optarg = strtok(optarg, ",:; \t\n\r\f")) != NULL) {
770 if (strcmp(optarg, "default") == 0) {
Mark Salyzyn45177732016-04-11 14:03:48 -0700771 idMask |= (1 << LOG_ID_MAIN) |
772 (1 << LOG_ID_SYSTEM) |
773 (1 << LOG_ID_CRASH);
Mark Salyzyn1325ebf2016-06-07 13:03:10 -0700774 } else if (strcmp(optarg, "all") == 0) {
Mark Salyzyn45177732016-04-11 14:03:48 -0700775 idMask = (unsigned)-1;
776 } else {
Mark Salyzyn1325ebf2016-06-07 13:03:10 -0700777 log_id_t log_id = android_name_to_log_id(optarg);
Mark Salyzyn45177732016-04-11 14:03:48 -0700778 const char *name = android_log_id_to_name(log_id);
Mark Salyzyn34facab2014-02-06 14:48:50 -0800779
Mark Salyzyn1325ebf2016-06-07 13:03:10 -0700780 if (strcmp(name, optarg) != 0) {
781 logcat_panic(true, "unknown buffer %s\n", optarg);
Mark Salyzyn34facab2014-02-06 14:48:50 -0800782 }
Mark Salyzyn45177732016-04-11 14:03:48 -0700783 idMask |= (1 << log_id);
Mark Salyzyn083b0372015-12-04 10:59:45 -0800784 }
Mark Salyzyn1325ebf2016-06-07 13:03:10 -0700785 optarg = NULL;
Mark Salyzyn083b0372015-12-04 10:59:45 -0800786 }
787
Mark Salyzyn45177732016-04-11 14:03:48 -0700788 for (int i = LOG_ID_MIN; i < LOG_ID_MAX; ++i) {
789 const char *name = android_log_id_to_name((log_id_t)i);
790 log_id_t log_id = android_name_to_log_id(name);
Mark Salyzyn083b0372015-12-04 10:59:45 -0800791
Mark Salyzyn45177732016-04-11 14:03:48 -0700792 if (log_id != (log_id_t)i) {
793 continue;
794 }
795 if ((idMask & (1 << i)) == 0) {
796 continue;
797 }
Mark Salyzyn083b0372015-12-04 10:59:45 -0800798
Mark Salyzyn45177732016-04-11 14:03:48 -0700799 bool found = false;
800 for (dev = devices; dev; dev = dev->next) {
801 if (!strcmp(name, dev->device)) {
802 found = true;
Mark Salyzyn083b0372015-12-04 10:59:45 -0800803 break;
804 }
Mark Salyzyn45177732016-04-11 14:03:48 -0700805 if (!dev->next) {
Mark Salyzyn083b0372015-12-04 10:59:45 -0800806 break;
807 }
Joe Onorato6fa09a02010-02-26 10:04:23 -0800808 }
Mark Salyzyn45177732016-04-11 14:03:48 -0700809 if (found) {
810 continue;
811 }
812
813 bool binary = !strcmp(name, "events") ||
814 !strcmp(name, "security");
815 log_device_t* d = new log_device_t(name, binary);
816
Mark Salyzyn083b0372015-12-04 10:59:45 -0800817 if (dev) {
Mark Salyzyn45177732016-04-11 14:03:48 -0700818 dev->next = d;
819 dev = d;
820 } else {
821 devices = dev = d;
Mark Salyzyn083b0372015-12-04 10:59:45 -0800822 }
Mark Salyzyn45177732016-04-11 14:03:48 -0700823 g_devCount++;
Joe Onorato6fa09a02010-02-26 10:04:23 -0800824 }
Joe Onorato6fa09a02010-02-26 10:04:23 -0800825 }
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800826 break;
827
828 case 'B':
Traian Schiau59763032015-04-10 15:51:39 +0300829 g_printBinary = 1;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800830 break;
831
832 case 'f':
Mark Salyzyn9812fc42015-10-06 08:59:02 -0700833 if ((tail_time == log_time::EPOCH) && (tail_lines == 0)) {
Mark Salyzynf3555d92015-05-27 07:39:56 -0700834 tail_time = lastLogTime(optarg);
835 }
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800836 // redirect output to a file
Traian Schiau59763032015-04-10 15:51:39 +0300837 g_outputFileName = optarg;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800838 break;
839
Mark Salyzyn1325ebf2016-06-07 13:03:10 -0700840 case 'r':
841 if (!getSizeTArg(optarg, &g_logRotateSizeKBytes, 1)) {
842 logcat_panic(true, "Invalid parameter %s to -r\n", optarg);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800843 }
844 break;
845
Mark Salyzyn1325ebf2016-06-07 13:03:10 -0700846 case 'n':
847 if (!getSizeTArg(optarg, &g_maxRotatedLogs, 1)) {
848 logcat_panic(true, "Invalid parameter %s to -n\n", optarg);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800849 }
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800850 break;
851
852 case 'v':
853 err = setLogFormat (optarg);
854 if (err < 0) {
Mark Salyzyn1325ebf2016-06-07 13:03:10 -0700855 logcat_panic(true, "Invalid parameter %s to -v\n", optarg);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800856 }
Mark Salyzyne1f20042015-05-06 08:40:40 -0700857 hasSetLogFormat |= err;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800858 break;
859
860 case 'Q':
861 /* this is a *hidden* option used to start a version of logcat */
862 /* in an emulated device only. it basically looks for androidboot.logcat= */
863 /* on the kernel command line. If something is found, it extracts a log filter */
864 /* and uses it to run the program. If nothing is found, the program should */
865 /* quit immediately */
866#define KERNEL_OPTION "androidboot.logcat="
867#define CONSOLE_OPTION "androidboot.console="
868 {
869 int fd;
870 char* logcat;
871 char* console;
872 int force_exit = 1;
873 static char cmdline[1024];
874
875 fd = open("/proc/cmdline", O_RDONLY);
876 if (fd >= 0) {
877 int n = read(fd, cmdline, sizeof(cmdline)-1 );
878 if (n < 0) n = 0;
879 cmdline[n] = 0;
880 close(fd);
881 } else {
882 cmdline[0] = 0;
883 }
884
885 logcat = strstr( cmdline, KERNEL_OPTION );
886 console = strstr( cmdline, CONSOLE_OPTION );
887 if (logcat != NULL) {
888 char* p = logcat + sizeof(KERNEL_OPTION)-1;;
889 char* q = strpbrk( p, " \t\n\r" );;
890
891 if (q != NULL)
892 *q = 0;
893
894 forceFilters = p;
895 force_exit = 0;
896 }
897 /* if nothing found or invalid filters, exit quietly */
Traian Schiau59763032015-04-10 15:51:39 +0300898 if (force_exit) {
899 return EXIT_SUCCESS;
900 }
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800901
902 /* redirect our output to the emulator console */
903 if (console) {
904 char* p = console + sizeof(CONSOLE_OPTION)-1;
905 char* q = strpbrk( p, " \t\n\r" );
906 char devname[64];
907 int len;
908
909 if (q != NULL) {
910 len = q - p;
911 } else
912 len = strlen(p);
913
914 len = snprintf( devname, sizeof(devname), "/dev/%.*s", len, p );
915 fprintf(stderr, "logcat using %s (%d)\n", devname, len);
916 if (len < (int)sizeof(devname)) {
917 fd = open( devname, O_WRONLY );
918 if (fd >= 0) {
919 dup2(fd, 1);
920 dup2(fd, 2);
921 close(fd);
922 }
923 }
924 }
925 }
926 break;
927
Mark Salyzyn34facab2014-02-06 14:48:50 -0800928 case 'S':
929 printStatistics = 1;
930 break;
931
Traian Schiau59763032015-04-10 15:51:39 +0300932 case ':':
933 logcat_panic(true, "Option -%c needs an argument\n", optopt);
934 break;
935
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800936 default:
Traian Schiau59763032015-04-10 15:51:39 +0300937 logcat_panic(true, "Unrecognized Option %c\n", optopt);
938 break;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800939 }
940 }
941
Casey Dahlin6ac498d2016-03-17 14:04:52 -0700942 if (g_maxCount && got_t) {
Mark Salyzynaa730c12016-03-30 12:38:29 -0700943 logcat_panic(true, "Cannot use -m (--max-count) and -t together\n");
Casey Dahlin6ac498d2016-03-17 14:04:52 -0700944 }
Mark Salyzync9202772016-03-30 09:38:31 -0700945 if (g_printItAnyways && (!g_regex || !g_maxCount)) {
946 // One day it would be nice if --print -v color and --regex <expr>
947 // could play with each other and show regex highlighted content.
948 fprintf(stderr, "WARNING: "
949 "--print ignored, to be used in combination with\n"
950 " "
951 "--regex <expr> and --max-count <N>\n");
952 g_printItAnyways = false;
953 }
Casey Dahlin6ac498d2016-03-17 14:04:52 -0700954
Joe Onorato6fa09a02010-02-26 10:04:23 -0800955 if (!devices) {
Mark Salyzyn5f6738a2015-02-27 13:41:34 -0800956 dev = devices = new log_device_t("main", false);
Traian Schiau59763032015-04-10 15:51:39 +0300957 g_devCount = 1;
Mark Salyzyn95132e92013-11-22 10:55:48 -0800958 if (android_name_to_log_id("system") == LOG_ID_SYSTEM) {
Mark Salyzyn5f6738a2015-02-27 13:41:34 -0800959 dev = dev->next = new log_device_t("system", false);
Traian Schiau59763032015-04-10 15:51:39 +0300960 g_devCount++;
Joe Onoratoe2bf2ea2010-03-01 09:11:54 -0800961 }
Mark Salyzyn99f47a92014-04-07 14:58:08 -0700962 if (android_name_to_log_id("crash") == LOG_ID_CRASH) {
Mark Salyzyn5f6738a2015-02-27 13:41:34 -0800963 dev = dev->next = new log_device_t("crash", false);
Traian Schiau59763032015-04-10 15:51:39 +0300964 g_devCount++;
Mark Salyzyn99f47a92014-04-07 14:58:08 -0700965 }
Joe Onorato6fa09a02010-02-26 10:04:23 -0800966 }
967
Traian Schiau59763032015-04-10 15:51:39 +0300968 if (g_logRotateSizeKBytes != 0 && g_outputFileName == NULL) {
969 logcat_panic(true, "-r requires -f as well\n");
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800970 }
971
Mark Salyzyn02687e72016-08-03 14:20:41 -0700972 if (setId != NULL) {
973 if (g_outputFileName == NULL) {
974 logcat_panic(true, "--id='%s' requires -f as well\n", setId);
975 }
976
977 std::string file_name = android::base::StringPrintf("%s.id", g_outputFileName);
978 std::string file;
979 bool file_ok = android::base::ReadFileToString(file_name, &file);
980 android::base::WriteStringToFile(setId, file_name,
981 S_IRUSR | S_IWUSR, getuid(), getgid());
982 if (!file_ok || (file.compare(setId) == 0)) {
983 setId = NULL;
984 }
985 }
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800986
987 if (hasSetLogFormat == 0) {
988 const char* logFormat = getenv("ANDROID_PRINTF_LOG");
989
990 if (logFormat != NULL) {
991 err = setLogFormat(logFormat);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800992 if (err < 0) {
Mark Salyzyn95132e92013-11-22 10:55:48 -0800993 fprintf(stderr, "invalid format in ANDROID_PRINTF_LOG '%s'\n",
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800994 logFormat);
995 }
Mark Salyzyn649fc602014-09-16 09:15:15 -0700996 } else {
997 setLogFormat("threadtime");
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800998 }
999 }
1000
1001 if (forceFilters) {
1002 err = android_log_addFilterString(g_logformat, forceFilters);
1003 if (err < 0) {
Traian Schiau59763032015-04-10 15:51:39 +03001004 logcat_panic(false, "Invalid filter expression in logcat args\n");
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001005 }
1006 } else if (argc == optind) {
1007 // Add from environment variable
1008 char *env_tags_orig = getenv("ANDROID_LOG_TAGS");
1009
1010 if (env_tags_orig != NULL) {
1011 err = android_log_addFilterString(g_logformat, env_tags_orig);
1012
Mark Salyzyn95132e92013-11-22 10:55:48 -08001013 if (err < 0) {
Traian Schiau59763032015-04-10 15:51:39 +03001014 logcat_panic(true,
1015 "Invalid filter expression in ANDROID_LOG_TAGS\n");
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001016 }
1017 }
1018 } else {
1019 // Add from commandline
1020 for (int i = optind ; i < argc ; i++) {
1021 err = android_log_addFilterString(g_logformat, argv[i]);
1022
Mark Salyzyn95132e92013-11-22 10:55:48 -08001023 if (err < 0) {
Traian Schiau59763032015-04-10 15:51:39 +03001024 logcat_panic(true, "Invalid filter expression '%s'\n", argv[i]);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001025 }
1026 }
1027 }
1028
Joe Onorato6fa09a02010-02-26 10:04:23 -08001029 dev = devices;
Mark Salyzynfa3716b2014-02-14 16:05:05 -08001030 if (tail_time != log_time::EPOCH) {
Kristian Monsen562e5132015-06-05 14:10:12 -07001031 logger_list = android_logger_list_alloc_time(mode, tail_time, pid);
Mark Salyzynfa3716b2014-02-14 16:05:05 -08001032 } else {
Kristian Monsen562e5132015-06-05 14:10:12 -07001033 logger_list = android_logger_list_alloc(mode, tail_lines, pid);
Mark Salyzynfa3716b2014-02-14 16:05:05 -08001034 }
Mark Salyzyn603b8e52015-09-16 15:34:00 -07001035 const char *openDeviceFail = NULL;
1036 const char *clearFail = NULL;
1037 const char *setSizeFail = NULL;
1038 const char *getSizeFail = NULL;
1039 // We have three orthogonal actions below to clear, set log size and
1040 // get log size. All sharing the same iteration loop.
Joe Onorato6fa09a02010-02-26 10:04:23 -08001041 while (dev) {
Mark Salyzyn95132e92013-11-22 10:55:48 -08001042 dev->logger_list = logger_list;
1043 dev->logger = android_logger_open(logger_list,
1044 android_name_to_log_id(dev->device));
1045 if (!dev->logger) {
Mark Salyzyn603b8e52015-09-16 15:34:00 -07001046 openDeviceFail = openDeviceFail ?: dev->device;
1047 dev = dev->next;
1048 continue;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001049 }
Joe Onorato6fa09a02010-02-26 10:04:23 -08001050
Mark Salyzyn02687e72016-08-03 14:20:41 -07001051 if (clearLog || setId) {
Mark Salyzynb7d059b2016-06-06 14:56:00 -07001052 if (g_outputFileName) {
1053 int maxRotationCountDigits =
1054 (g_maxRotatedLogs > 0) ? (int) (floor(log10(g_maxRotatedLogs) + 1)) : 0;
1055
1056 for (int i = g_maxRotatedLogs ; i >= 0 ; --i) {
Mark Salyzyn5b1a5382016-08-03 14:20:41 -07001057 std::string file;
Mark Salyzynb7d059b2016-06-06 14:56:00 -07001058
1059 if (i == 0) {
Mark Salyzyn5b1a5382016-08-03 14:20:41 -07001060 file = android::base::StringPrintf("%s", g_outputFileName);
Mark Salyzynb7d059b2016-06-06 14:56:00 -07001061 } else {
Mark Salyzyn5b1a5382016-08-03 14:20:41 -07001062 file = android::base::StringPrintf("%s.%.*d",
1063 g_outputFileName, maxRotationCountDigits, i);
Mark Salyzynb7d059b2016-06-06 14:56:00 -07001064 }
1065
Mark Salyzyn5b1a5382016-08-03 14:20:41 -07001066 if (file.length() == 0) {
Mark Salyzynb7d059b2016-06-06 14:56:00 -07001067 perror("while clearing log files");
1068 clearFail = clearFail ?: dev->device;
1069 break;
1070 }
1071
Mark Salyzyn5b1a5382016-08-03 14:20:41 -07001072 err = unlink(file.c_str());
Mark Salyzynb7d059b2016-06-06 14:56:00 -07001073
1074 if (err < 0 && errno != ENOENT && clearFail == NULL) {
1075 perror("while clearing log files");
1076 clearFail = dev->device;
1077 }
Mark Salyzynb7d059b2016-06-06 14:56:00 -07001078 }
1079 } else if (android_logger_clear(dev->logger)) {
Mark Salyzyn603b8e52015-09-16 15:34:00 -07001080 clearFail = clearFail ?: dev->device;
Joe Onorato6fa09a02010-02-26 10:04:23 -08001081 }
Joe Onorato6fa09a02010-02-26 10:04:23 -08001082 }
1083
Mark Salyzyn603b8e52015-09-16 15:34:00 -07001084 if (setLogSize) {
1085 if (android_logger_set_log_size(dev->logger, setLogSize)) {
1086 setSizeFail = setSizeFail ?: dev->device;
1087 }
Mark Salyzyndfa7a072014-02-11 12:29:31 -08001088 }
1089
Joe Onorato6fa09a02010-02-26 10:04:23 -08001090 if (getLogSize) {
Mark Salyzyn603b8e52015-09-16 15:34:00 -07001091 long size = android_logger_get_log_size(dev->logger);
1092 long readable = android_logger_get_log_readable_size(dev->logger);
Joe Onorato6fa09a02010-02-26 10:04:23 -08001093
Mark Salyzyn603b8e52015-09-16 15:34:00 -07001094 if ((size < 0) || (readable < 0)) {
1095 getSizeFail = getSizeFail ?: dev->device;
1096 } else {
1097 printf("%s: ring buffer is %ld%sb (%ld%sb consumed), "
1098 "max entry is %db, max payload is %db\n", dev->device,
1099 value_of_size(size), multiplier_of_size(size),
1100 value_of_size(readable), multiplier_of_size(readable),
1101 (int) LOGGER_ENTRY_MAX_LEN,
1102 (int) LOGGER_ENTRY_MAX_PAYLOAD);
Joe Onorato6fa09a02010-02-26 10:04:23 -08001103 }
Joe Onorato6fa09a02010-02-26 10:04:23 -08001104 }
1105
1106 dev = dev->next;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001107 }
Mark Salyzyn603b8e52015-09-16 15:34:00 -07001108 // report any errors in the above loop and exit
1109 if (openDeviceFail) {
1110 logcat_panic(false, "Unable to open log device '%s'\n", openDeviceFail);
1111 }
1112 if (clearFail) {
1113 logcat_panic(false, "failed to clear the '%s' log\n", clearFail);
1114 }
1115 if (setSizeFail) {
1116 logcat_panic(false, "failed to set the '%s' log size\n", setSizeFail);
1117 }
1118 if (getSizeFail) {
1119 logcat_panic(false, "failed to get the readable '%s' log size",
1120 getSizeFail);
1121 }
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001122
Mark Salyzyndfa7a072014-02-11 12:29:31 -08001123 if (setPruneList) {
Traian Schiau59763032015-04-10 15:51:39 +03001124 size_t len = strlen(setPruneList);
1125 /*extra 32 bytes are needed by android_logger_set_prune_list */
1126 size_t bLen = len + 32;
1127 char *buf = NULL;
1128 if (asprintf(&buf, "%-*s", (int)(bLen - 1), setPruneList) > 0) {
1129 buf[len] = '\0';
1130 if (android_logger_set_prune_list(logger_list, buf, bLen)) {
1131 logcat_panic(false, "failed to set the prune list");
1132 }
1133 free(buf);
1134 } else {
1135 logcat_panic(false, "failed to set the prune list (alloc)");
Mark Salyzyndfa7a072014-02-11 12:29:31 -08001136 }
1137 }
1138
Mark Salyzyn1c950472014-04-01 17:19:47 -07001139 if (printStatistics || getPruneList) {
Mark Salyzyn34facab2014-02-06 14:48:50 -08001140 size_t len = 8192;
1141 char *buf;
1142
Mark Salyzyn083b0372015-12-04 10:59:45 -08001143 for (int retry = 32;
Mark Salyzyn34facab2014-02-06 14:48:50 -08001144 (retry >= 0) && ((buf = new char [len]));
Traian Schiau59763032015-04-10 15:51:39 +03001145 delete [] buf, buf = NULL, --retry) {
Mark Salyzyndfa7a072014-02-11 12:29:31 -08001146 if (getPruneList) {
1147 android_logger_get_prune_list(logger_list, buf, len);
1148 } else {
1149 android_logger_get_statistics(logger_list, buf, len);
1150 }
Mark Salyzyn34facab2014-02-06 14:48:50 -08001151 buf[len-1] = '\0';
Traian Schiau59763032015-04-10 15:51:39 +03001152 if (atol(buf) < 3) {
Mark Salyzyn34facab2014-02-06 14:48:50 -08001153 delete [] buf;
1154 buf = NULL;
1155 break;
1156 }
Traian Schiau59763032015-04-10 15:51:39 +03001157 size_t ret = atol(buf) + 1;
1158 if (ret <= len) {
1159 len = ret;
Mark Salyzyn34facab2014-02-06 14:48:50 -08001160 break;
1161 }
Traian Schiau59763032015-04-10 15:51:39 +03001162 len = ret;
Mark Salyzyn34facab2014-02-06 14:48:50 -08001163 }
1164
1165 if (!buf) {
Traian Schiau59763032015-04-10 15:51:39 +03001166 logcat_panic(false, "failed to read data");
Mark Salyzyn34facab2014-02-06 14:48:50 -08001167 }
1168
1169 // remove trailing FF
1170 char *cp = buf + len - 1;
1171 *cp = '\0';
1172 bool truncated = *--cp != '\f';
1173 if (!truncated) {
1174 *cp = '\0';
1175 }
1176
1177 // squash out the byte count
1178 cp = buf;
1179 if (!truncated) {
Mark Salyzyn22e287d2014-03-21 13:12:16 -07001180 while (isdigit(*cp)) {
1181 ++cp;
1182 }
1183 if (*cp == '\n') {
Mark Salyzyn34facab2014-02-06 14:48:50 -08001184 ++cp;
1185 }
1186 }
1187
1188 printf("%s", cp);
1189 delete [] buf;
Traian Schiau59763032015-04-10 15:51:39 +03001190 return EXIT_SUCCESS;
Mark Salyzyn34facab2014-02-06 14:48:50 -08001191 }
1192
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001193 if (getLogSize) {
Traian Schiau59763032015-04-10 15:51:39 +03001194 return EXIT_SUCCESS;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001195 }
Mark Salyzyndfa7a072014-02-11 12:29:31 -08001196 if (setLogSize || setPruneList) {
Traian Schiau59763032015-04-10 15:51:39 +03001197 return EXIT_SUCCESS;
Mark Salyzyndfa7a072014-02-11 12:29:31 -08001198 }
Joe Onoratoe2bf2ea2010-03-01 09:11:54 -08001199 if (clearLog) {
Traian Schiau59763032015-04-10 15:51:39 +03001200 return EXIT_SUCCESS;
Joe Onoratoe2bf2ea2010-03-01 09:11:54 -08001201 }
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001202
Mark Salyzynad5e4112016-08-04 07:53:52 -07001203 setupOutputAndSchedulingPolicy((mode & ANDROID_LOG_NONBLOCK) == 0);
Mark Salyzyn02687e72016-08-03 14:20:41 -07001204
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001205 //LOG_EVENT_INT(10, 12345);
1206 //LOG_EVENT_LONG(11, 0x1122334455667788LL);
1207 //LOG_EVENT_STRING(0, "whassup, doc?");
1208
Mark Salyzyn7b30ff82015-01-26 13:41:33 -08001209 dev = NULL;
Mark Salyzyn5f6738a2015-02-27 13:41:34 -08001210 log_device_t unexpected("unexpected", false);
Casey Dahlin6ac498d2016-03-17 14:04:52 -07001211
Mark Salyzynaa730c12016-03-30 12:38:29 -07001212 while (!g_maxCount || (g_printCount < g_maxCount)) {
Mark Salyzyn95132e92013-11-22 10:55:48 -08001213 struct log_msg log_msg;
Mark Salyzyn7b30ff82015-01-26 13:41:33 -08001214 log_device_t* d;
Mark Salyzyn95132e92013-11-22 10:55:48 -08001215 int ret = android_logger_list_read(logger_list, &log_msg);
1216
1217 if (ret == 0) {
Traian Schiau59763032015-04-10 15:51:39 +03001218 logcat_panic(false, "read: unexpected EOF!\n");
Mark Salyzyn95132e92013-11-22 10:55:48 -08001219 }
1220
1221 if (ret < 0) {
1222 if (ret == -EAGAIN) {
1223 break;
1224 }
1225
1226 if (ret == -EIO) {
Traian Schiau59763032015-04-10 15:51:39 +03001227 logcat_panic(false, "read: unexpected EOF!\n");
Mark Salyzyn95132e92013-11-22 10:55:48 -08001228 }
1229 if (ret == -EINVAL) {
Traian Schiau59763032015-04-10 15:51:39 +03001230 logcat_panic(false, "read: unexpected length.\n");
Mark Salyzyn95132e92013-11-22 10:55:48 -08001231 }
Traian Schiau59763032015-04-10 15:51:39 +03001232 logcat_panic(false, "logcat read failure");
Mark Salyzyn95132e92013-11-22 10:55:48 -08001233 }
1234
Mark Salyzyn083b0372015-12-04 10:59:45 -08001235 for (d = devices; d; d = d->next) {
Mark Salyzyn7b30ff82015-01-26 13:41:33 -08001236 if (android_name_to_log_id(d->device) == log_msg.id()) {
Mark Salyzyn95132e92013-11-22 10:55:48 -08001237 break;
1238 }
1239 }
Mark Salyzyn7b30ff82015-01-26 13:41:33 -08001240 if (!d) {
Traian Schiau59763032015-04-10 15:51:39 +03001241 g_devCount = 2; // set to Multiple
Mark Salyzyn9421b0c2015-02-26 14:33:35 -08001242 d = &unexpected;
1243 d->binary = log_msg.id() == LOG_ID_EVENTS;
Mark Salyzyn95132e92013-11-22 10:55:48 -08001244 }
1245
Mark Salyzyn7b30ff82015-01-26 13:41:33 -08001246 if (dev != d) {
1247 dev = d;
Traian Schiau59763032015-04-10 15:51:39 +03001248 maybePrintStart(dev, printDividers);
Mark Salyzyn7b30ff82015-01-26 13:41:33 -08001249 }
Traian Schiau59763032015-04-10 15:51:39 +03001250 if (g_printBinary) {
1251 printBinary(&log_msg);
Mark Salyzyn95132e92013-11-22 10:55:48 -08001252 } else {
Traian Schiau59763032015-04-10 15:51:39 +03001253 processBuffer(dev, &log_msg);
Mark Salyzyn95132e92013-11-22 10:55:48 -08001254 }
1255 }
1256
1257 android_logger_list_free(logger_list);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001258
Traian Schiau59763032015-04-10 15:51:39 +03001259 return EXIT_SUCCESS;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001260}