Mark Salyzyn | 4295841 | 2013-11-22 10:50:27 -0800 | [diff] [blame] | 1 | /* |
| 2 | ** |
Mark Salyzyn | e9c4196 | 2014-01-02 13:52:29 -0800 | [diff] [blame] | 3 | ** Copyright 2007-2014, The Android Open Source Project |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 4 | ** |
| 5 | ** This file is dual licensed. It may be redistributed and/or modified |
| 6 | ** under the terms of the Apache 2.0 License OR version 2 of the GNU |
| 7 | ** General Public License. |
| 8 | */ |
| 9 | |
Mark Salyzyn | 318bb72 | 2014-01-10 14:07:58 -0800 | [diff] [blame] | 10 | #ifndef _LIBS_LOG_LOGGER_H |
| 11 | #define _LIBS_LOG_LOGGER_H |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 12 | |
| 13 | #include <stdint.h> |
Mark Salyzyn | 004cd3c | 2016-09-28 08:38:21 -0700 | [diff] [blame^] | 14 | #include <time.h> |
Mark Salyzyn | ba7a9a0 | 2015-12-01 15:57:25 -0800 | [diff] [blame] | 15 | |
Mark Salyzyn | 8eaaac0 | 2016-09-27 11:18:29 -0700 | [diff] [blame] | 16 | #ifdef __cplusplus |
| 17 | #include <string> |
| 18 | #endif |
| 19 | |
Mark Salyzyn | 4295841 | 2013-11-22 10:50:27 -0800 | [diff] [blame] | 20 | #include <log/log.h> |
| 21 | |
Mark Salyzyn | f387fa5 | 2014-01-03 16:54:28 -0800 | [diff] [blame] | 22 | #ifdef __cplusplus |
| 23 | extern "C" { |
| 24 | #endif |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 25 | |
Nick Kralevich | 6756a0c | 2012-03-22 14:28:16 -0700 | [diff] [blame] | 26 | /* |
| 27 | * The userspace structure for version 1 of the logger_entry ABI. |
| 28 | * This structure is returned to userspace by the kernel logger |
| 29 | * driver unless an upgrade to a newer ABI version is requested. |
| 30 | */ |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 31 | struct logger_entry { |
| 32 | uint16_t len; /* length of the payload */ |
| 33 | uint16_t __pad; /* no matter what, we get 2 bytes of padding */ |
| 34 | int32_t pid; /* generating process's pid */ |
| 35 | int32_t tid; /* generating process's tid */ |
| 36 | int32_t sec; /* seconds since Epoch */ |
| 37 | int32_t nsec; /* nanoseconds */ |
| 38 | char msg[0]; /* the entry's payload */ |
Mark Salyzyn | 7e2f83c | 2014-03-05 07:41:49 -0800 | [diff] [blame] | 39 | } __attribute__((__packed__)); |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 40 | |
Nick Kralevich | 6756a0c | 2012-03-22 14:28:16 -0700 | [diff] [blame] | 41 | /* |
| 42 | * The userspace structure for version 2 of the logger_entry ABI. |
| 43 | * This structure is returned to userspace if ioctl(LOGGER_SET_VERSION) |
Mark Salyzyn | 0175b07 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 44 | * is called with version==2; or used with the user space log daemon. |
Nick Kralevich | 6756a0c | 2012-03-22 14:28:16 -0700 | [diff] [blame] | 45 | */ |
| 46 | struct logger_entry_v2 { |
| 47 | uint16_t len; /* length of the payload */ |
| 48 | uint16_t hdr_size; /* sizeof(struct logger_entry_v2) */ |
| 49 | int32_t pid; /* generating process's pid */ |
| 50 | int32_t tid; /* generating process's tid */ |
| 51 | int32_t sec; /* seconds since Epoch */ |
| 52 | int32_t nsec; /* nanoseconds */ |
| 53 | uint32_t euid; /* effective UID of logger */ |
| 54 | char msg[0]; /* the entry's payload */ |
Mark Salyzyn | 7e2f83c | 2014-03-05 07:41:49 -0800 | [diff] [blame] | 55 | } __attribute__((__packed__)); |
Nick Kralevich | 6756a0c | 2012-03-22 14:28:16 -0700 | [diff] [blame] | 56 | |
Mark Salyzyn | 0175b07 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 57 | struct logger_entry_v3 { |
| 58 | uint16_t len; /* length of the payload */ |
Mark Salyzyn | 7e2f83c | 2014-03-05 07:41:49 -0800 | [diff] [blame] | 59 | uint16_t hdr_size; /* sizeof(struct logger_entry_v3) */ |
Mark Salyzyn | 0175b07 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 60 | int32_t pid; /* generating process's pid */ |
| 61 | int32_t tid; /* generating process's tid */ |
| 62 | int32_t sec; /* seconds since Epoch */ |
| 63 | int32_t nsec; /* nanoseconds */ |
| 64 | uint32_t lid; /* log id of the payload */ |
| 65 | char msg[0]; /* the entry's payload */ |
Mark Salyzyn | 7e2f83c | 2014-03-05 07:41:49 -0800 | [diff] [blame] | 66 | } __attribute__((__packed__)); |
Mark Salyzyn | 0175b07 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 67 | |
Mark Salyzyn | 9b292f5 | 2015-12-03 15:37:00 -0800 | [diff] [blame] | 68 | struct logger_entry_v4 { |
| 69 | uint16_t len; /* length of the payload */ |
| 70 | uint16_t hdr_size; /* sizeof(struct logger_entry_v4) */ |
| 71 | int32_t pid; /* generating process's pid */ |
| 72 | uint32_t tid; /* generating process's tid */ |
| 73 | uint32_t sec; /* seconds since Epoch */ |
| 74 | uint32_t nsec; /* nanoseconds */ |
| 75 | uint32_t lid; /* log id of the payload, bottom 4 bits currently */ |
| 76 | uint32_t uid; /* generating process's uid */ |
| 77 | char msg[0]; /* the entry's payload */ |
| 78 | } __attribute__((__packed__)); |
| 79 | |
Mark Salyzyn | 004cd3c | 2016-09-28 08:38:21 -0700 | [diff] [blame^] | 80 | /* struct log_time is a wire-format variant of struct timespec */ |
| 81 | #define NS_PER_SEC 1000000000ULL |
| 82 | |
| 83 | #ifdef __cplusplus |
| 84 | |
| 85 | // NB: do NOT define a copy constructor. This will result in structure |
| 86 | // no longer being compatible with pass-by-value which is desired |
| 87 | // efficient behavior. Also, pass-by-reference breaks C/C++ ABI. |
| 88 | struct log_time { |
| 89 | public: |
| 90 | uint32_t tv_sec; // good to Feb 5 2106 |
| 91 | uint32_t tv_nsec; |
| 92 | |
| 93 | static const uint32_t tv_sec_max = 0xFFFFFFFFUL; |
| 94 | static const uint32_t tv_nsec_max = 999999999UL; |
| 95 | |
| 96 | log_time(const timespec &T) |
| 97 | { |
| 98 | tv_sec = T.tv_sec; |
| 99 | tv_nsec = T.tv_nsec; |
| 100 | } |
| 101 | log_time(uint32_t sec, uint32_t nsec) |
| 102 | { |
| 103 | tv_sec = sec; |
| 104 | tv_nsec = nsec; |
| 105 | } |
| 106 | static const timespec EPOCH; |
| 107 | log_time() |
| 108 | { |
| 109 | } |
| 110 | #ifdef __linux__ |
| 111 | log_time(clockid_t id) |
| 112 | { |
| 113 | timespec T; |
| 114 | clock_gettime(id, &T); |
| 115 | tv_sec = T.tv_sec; |
| 116 | tv_nsec = T.tv_nsec; |
| 117 | } |
| 118 | #endif |
| 119 | log_time(const char *T) |
| 120 | { |
| 121 | const uint8_t *c = (const uint8_t *) T; |
| 122 | tv_sec = c[0] | (c[1] << 8) | (c[2] << 16) | (c[3] << 24); |
| 123 | tv_nsec = c[4] | (c[5] << 8) | (c[6] << 16) | (c[7] << 24); |
| 124 | } |
| 125 | |
| 126 | // timespec |
| 127 | bool operator== (const timespec &T) const |
| 128 | { |
| 129 | return (tv_sec == static_cast<uint32_t>(T.tv_sec)) |
| 130 | && (tv_nsec == static_cast<uint32_t>(T.tv_nsec)); |
| 131 | } |
| 132 | bool operator!= (const timespec &T) const |
| 133 | { |
| 134 | return !(*this == T); |
| 135 | } |
| 136 | bool operator< (const timespec &T) const |
| 137 | { |
| 138 | return (tv_sec < static_cast<uint32_t>(T.tv_sec)) |
| 139 | || ((tv_sec == static_cast<uint32_t>(T.tv_sec)) |
| 140 | && (tv_nsec < static_cast<uint32_t>(T.tv_nsec))); |
| 141 | } |
| 142 | bool operator>= (const timespec &T) const |
| 143 | { |
| 144 | return !(*this < T); |
| 145 | } |
| 146 | bool operator> (const timespec &T) const |
| 147 | { |
| 148 | return (tv_sec > static_cast<uint32_t>(T.tv_sec)) |
| 149 | || ((tv_sec == static_cast<uint32_t>(T.tv_sec)) |
| 150 | && (tv_nsec > static_cast<uint32_t>(T.tv_nsec))); |
| 151 | } |
| 152 | bool operator<= (const timespec &T) const |
| 153 | { |
| 154 | return !(*this > T); |
| 155 | } |
| 156 | log_time operator-= (const timespec &T); |
| 157 | log_time operator- (const timespec &T) const |
| 158 | { |
| 159 | log_time local(*this); |
| 160 | return local -= T; |
| 161 | } |
| 162 | log_time operator+= (const timespec &T); |
| 163 | log_time operator+ (const timespec &T) const |
| 164 | { |
| 165 | log_time local(*this); |
| 166 | return local += T; |
| 167 | } |
| 168 | |
| 169 | // log_time |
| 170 | bool operator== (const log_time &T) const |
| 171 | { |
| 172 | return (tv_sec == T.tv_sec) && (tv_nsec == T.tv_nsec); |
| 173 | } |
| 174 | bool operator!= (const log_time &T) const |
| 175 | { |
| 176 | return !(*this == T); |
| 177 | } |
| 178 | bool operator< (const log_time &T) const |
| 179 | { |
| 180 | return (tv_sec < T.tv_sec) |
| 181 | || ((tv_sec == T.tv_sec) && (tv_nsec < T.tv_nsec)); |
| 182 | } |
| 183 | bool operator>= (const log_time &T) const |
| 184 | { |
| 185 | return !(*this < T); |
| 186 | } |
| 187 | bool operator> (const log_time &T) const |
| 188 | { |
| 189 | return (tv_sec > T.tv_sec) |
| 190 | || ((tv_sec == T.tv_sec) && (tv_nsec > T.tv_nsec)); |
| 191 | } |
| 192 | bool operator<= (const log_time &T) const |
| 193 | { |
| 194 | return !(*this > T); |
| 195 | } |
| 196 | log_time operator-= (const log_time &T); |
| 197 | log_time operator- (const log_time &T) const |
| 198 | { |
| 199 | log_time local(*this); |
| 200 | return local -= T; |
| 201 | } |
| 202 | log_time operator+= (const log_time &T); |
| 203 | log_time operator+ (const log_time &T) const |
| 204 | { |
| 205 | log_time local(*this); |
| 206 | return local += T; |
| 207 | } |
| 208 | |
| 209 | uint64_t nsec() const |
| 210 | { |
| 211 | return static_cast<uint64_t>(tv_sec) * NS_PER_SEC + tv_nsec; |
| 212 | } |
| 213 | |
| 214 | static const char default_format[]; |
| 215 | |
| 216 | // Add %#q for the fraction of a second to the standard library functions |
| 217 | char *strptime(const char *s, const char *format = default_format); |
| 218 | } __attribute__((__packed__)); |
| 219 | |
| 220 | #else |
| 221 | |
| 222 | typedef struct log_time { |
| 223 | uint32_t tv_sec; |
| 224 | uint32_t tv_nsec; |
| 225 | } __attribute__((__packed__)) log_time; |
| 226 | |
| 227 | #endif |
| 228 | |
Nick Kralevich | 6756a0c | 2012-03-22 14:28:16 -0700 | [diff] [blame] | 229 | /* |
| 230 | * The maximum size of the log entry payload that can be |
Mark Salyzyn | 4887842 | 2014-05-22 16:08:52 -0700 | [diff] [blame] | 231 | * written to the logger. An attempt to write more than |
| 232 | * this amount will result in a truncated log entry. |
Nick Kralevich | 6756a0c | 2012-03-22 14:28:16 -0700 | [diff] [blame] | 233 | */ |
Mark Salyzyn | 8eaaac0 | 2016-09-27 11:18:29 -0700 | [diff] [blame] | 234 | #define LOGGER_ENTRY_MAX_PAYLOAD 4068 |
Nick Kralevich | 6756a0c | 2012-03-22 14:28:16 -0700 | [diff] [blame] | 235 | |
| 236 | /* |
| 237 | * The maximum size of a log entry which can be read from the |
| 238 | * kernel logger driver. An attempt to read less than this amount |
| 239 | * may result in read() returning EINVAL. |
| 240 | */ |
Mark Salyzyn | 8eaaac0 | 2016-09-27 11:18:29 -0700 | [diff] [blame] | 241 | #define LOGGER_ENTRY_MAX_LEN (5*1024) |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 242 | |
Mark Salyzyn | 4295841 | 2013-11-22 10:50:27 -0800 | [diff] [blame] | 243 | struct log_msg { |
| 244 | union { |
| 245 | unsigned char buf[LOGGER_ENTRY_MAX_LEN + 1]; |
Mark Salyzyn | 9b292f5 | 2015-12-03 15:37:00 -0800 | [diff] [blame] | 246 | struct logger_entry_v4 entry; |
| 247 | struct logger_entry_v4 entry_v4; |
Mark Salyzyn | 0175b07 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 248 | struct logger_entry_v3 entry_v3; |
Mark Salyzyn | 4295841 | 2013-11-22 10:50:27 -0800 | [diff] [blame] | 249 | struct logger_entry_v2 entry_v2; |
| 250 | struct logger_entry entry_v1; |
Mark Salyzyn | 4295841 | 2013-11-22 10:50:27 -0800 | [diff] [blame] | 251 | } __attribute__((aligned(4))); |
| 252 | #ifdef __cplusplus |
Mark Salyzyn | 318bb72 | 2014-01-10 14:07:58 -0800 | [diff] [blame] | 253 | /* Matching log_time operators */ |
| 254 | bool operator== (const log_msg &T) const |
Mark Salyzyn | 4295841 | 2013-11-22 10:50:27 -0800 | [diff] [blame] | 255 | { |
| 256 | return (entry.sec == T.entry.sec) && (entry.nsec == T.entry.nsec); |
| 257 | } |
Mark Salyzyn | 318bb72 | 2014-01-10 14:07:58 -0800 | [diff] [blame] | 258 | bool operator!= (const log_msg &T) const |
Mark Salyzyn | 4295841 | 2013-11-22 10:50:27 -0800 | [diff] [blame] | 259 | { |
| 260 | return !(*this == T); |
| 261 | } |
Mark Salyzyn | 318bb72 | 2014-01-10 14:07:58 -0800 | [diff] [blame] | 262 | bool operator< (const log_msg &T) const |
Mark Salyzyn | 4295841 | 2013-11-22 10:50:27 -0800 | [diff] [blame] | 263 | { |
| 264 | return (entry.sec < T.entry.sec) |
| 265 | || ((entry.sec == T.entry.sec) |
| 266 | && (entry.nsec < T.entry.nsec)); |
| 267 | } |
Mark Salyzyn | 318bb72 | 2014-01-10 14:07:58 -0800 | [diff] [blame] | 268 | bool operator>= (const log_msg &T) const |
Mark Salyzyn | 4295841 | 2013-11-22 10:50:27 -0800 | [diff] [blame] | 269 | { |
| 270 | return !(*this < T); |
| 271 | } |
Mark Salyzyn | 318bb72 | 2014-01-10 14:07:58 -0800 | [diff] [blame] | 272 | bool operator> (const log_msg &T) const |
Mark Salyzyn | 4295841 | 2013-11-22 10:50:27 -0800 | [diff] [blame] | 273 | { |
| 274 | return (entry.sec > T.entry.sec) |
| 275 | || ((entry.sec == T.entry.sec) |
| 276 | && (entry.nsec > T.entry.nsec)); |
| 277 | } |
Mark Salyzyn | 318bb72 | 2014-01-10 14:07:58 -0800 | [diff] [blame] | 278 | bool operator<= (const log_msg &T) const |
Mark Salyzyn | 4295841 | 2013-11-22 10:50:27 -0800 | [diff] [blame] | 279 | { |
| 280 | return !(*this > T); |
| 281 | } |
Mark Salyzyn | 0175b07 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 282 | uint64_t nsec() const |
Mark Salyzyn | 4295841 | 2013-11-22 10:50:27 -0800 | [diff] [blame] | 283 | { |
| 284 | return static_cast<uint64_t>(entry.sec) * NS_PER_SEC + entry.nsec; |
| 285 | } |
| 286 | |
| 287 | /* packet methods */ |
Mark Salyzyn | 0175b07 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 288 | log_id_t id() |
Mark Salyzyn | 4295841 | 2013-11-22 10:50:27 -0800 | [diff] [blame] | 289 | { |
Mark Salyzyn | 154f460 | 2014-02-20 14:59:07 -0800 | [diff] [blame] | 290 | return (log_id_t) entry.lid; |
Mark Salyzyn | 4295841 | 2013-11-22 10:50:27 -0800 | [diff] [blame] | 291 | } |
Mark Salyzyn | 0175b07 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 292 | char *msg() |
Mark Salyzyn | 4295841 | 2013-11-22 10:50:27 -0800 | [diff] [blame] | 293 | { |
Mark Salyzyn | 305374c | 2016-08-18 14:59:41 -0700 | [diff] [blame] | 294 | unsigned short hdr_size = entry.hdr_size; |
| 295 | if (!hdr_size) { |
| 296 | hdr_size = sizeof(entry_v1); |
| 297 | } |
| 298 | if ((hdr_size < sizeof(entry_v1)) || (hdr_size > sizeof(entry))) { |
| 299 | return NULL; |
| 300 | } |
| 301 | return (char *) buf + hdr_size; |
Mark Salyzyn | 4295841 | 2013-11-22 10:50:27 -0800 | [diff] [blame] | 302 | } |
Mark Salyzyn | 0175b07 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 303 | unsigned int len() |
Mark Salyzyn | 4295841 | 2013-11-22 10:50:27 -0800 | [diff] [blame] | 304 | { |
| 305 | return (entry.hdr_size ? entry.hdr_size : sizeof(entry_v1)) + entry.len; |
| 306 | } |
| 307 | #endif |
| 308 | }; |
| 309 | |
| 310 | struct logger; |
| 311 | |
| 312 | log_id_t android_logger_get_id(struct logger *logger); |
| 313 | |
| 314 | int android_logger_clear(struct logger *logger); |
Mark Salyzyn | dfa7a07 | 2014-02-11 12:29:31 -0800 | [diff] [blame] | 315 | long android_logger_get_log_size(struct logger *logger); |
Mark Salyzyn | dfa7a07 | 2014-02-11 12:29:31 -0800 | [diff] [blame] | 316 | int android_logger_set_log_size(struct logger *logger, unsigned long size); |
Mark Salyzyn | dfa7a07 | 2014-02-11 12:29:31 -0800 | [diff] [blame] | 317 | long android_logger_get_log_readable_size(struct logger *logger); |
Mark Salyzyn | 4295841 | 2013-11-22 10:50:27 -0800 | [diff] [blame] | 318 | int android_logger_get_log_version(struct logger *logger); |
| 319 | |
| 320 | struct logger_list; |
| 321 | |
Mark Salyzyn | 34facab | 2014-02-06 14:48:50 -0800 | [diff] [blame] | 322 | ssize_t android_logger_get_statistics(struct logger_list *logger_list, |
| 323 | char *buf, size_t len); |
Mark Salyzyn | dfa7a07 | 2014-02-11 12:29:31 -0800 | [diff] [blame] | 324 | ssize_t android_logger_get_prune_list(struct logger_list *logger_list, |
| 325 | char *buf, size_t len); |
| 326 | int android_logger_set_prune_list(struct logger_list *logger_list, |
| 327 | char *buf, size_t len); |
Mark Salyzyn | 34facab | 2014-02-06 14:48:50 -0800 | [diff] [blame] | 328 | |
Mark Salyzyn | 2d3f38a | 2015-01-26 10:46:44 -0800 | [diff] [blame] | 329 | #define ANDROID_LOG_RDONLY O_RDONLY |
| 330 | #define ANDROID_LOG_WRONLY O_WRONLY |
| 331 | #define ANDROID_LOG_RDWR O_RDWR |
| 332 | #define ANDROID_LOG_ACCMODE O_ACCMODE |
| 333 | #define ANDROID_LOG_NONBLOCK O_NONBLOCK |
Mark Salyzyn | f8e546e | 2015-11-30 11:36:09 -0800 | [diff] [blame] | 334 | #define ANDROID_LOG_WRAP 0x40000000 /* Block until buffer about to wrap */ |
| 335 | #define ANDROID_LOG_WRAP_DEFAULT_TIMEOUT 7200 /* 2 hour default */ |
Mark Salyzyn | 6eef417 | 2014-12-15 09:51:39 -0800 | [diff] [blame] | 336 | #define ANDROID_LOG_PSTORE 0x80000000 |
Mark Salyzyn | 2d3f38a | 2015-01-26 10:46:44 -0800 | [diff] [blame] | 337 | |
Mark Salyzyn | 4295841 | 2013-11-22 10:50:27 -0800 | [diff] [blame] | 338 | struct logger_list *android_logger_list_alloc(int mode, |
| 339 | unsigned int tail, |
| 340 | pid_t pid); |
Mark Salyzyn | fa3716b | 2014-02-14 16:05:05 -0800 | [diff] [blame] | 341 | struct logger_list *android_logger_list_alloc_time(int mode, |
| 342 | log_time start, |
| 343 | pid_t pid); |
Mark Salyzyn | 4295841 | 2013-11-22 10:50:27 -0800 | [diff] [blame] | 344 | void android_logger_list_free(struct logger_list *logger_list); |
| 345 | /* In the purest sense, the following two are orthogonal interfaces */ |
| 346 | int android_logger_list_read(struct logger_list *logger_list, |
| 347 | struct log_msg *log_msg); |
| 348 | |
| 349 | /* Multiple log_id_t opens */ |
| 350 | struct logger *android_logger_open(struct logger_list *logger_list, |
| 351 | log_id_t id); |
| 352 | #define android_logger_close android_logger_free |
| 353 | /* Single log_id_t open */ |
| 354 | struct logger_list *android_logger_list_open(log_id_t id, |
| 355 | int mode, |
| 356 | unsigned int tail, |
| 357 | pid_t pid); |
| 358 | #define android_logger_list_close android_logger_list_free |
| 359 | |
Mark Salyzyn | ba7a9a0 | 2015-12-01 15:57:25 -0800 | [diff] [blame] | 360 | #ifdef __linux__ |
| 361 | clockid_t android_log_clockid(); |
| 362 | #endif |
Mark Salyzyn | 500afc7 | 2015-09-08 08:32:01 -0700 | [diff] [blame] | 363 | |
Mark Salyzyn | 4295841 | 2013-11-22 10:50:27 -0800 | [diff] [blame] | 364 | /* |
| 365 | * log_id_t helpers |
| 366 | */ |
| 367 | log_id_t android_name_to_log_id(const char *logName); |
| 368 | const char *android_log_id_to_name(log_id_t log_id); |
| 369 | |
Mark Salyzyn | f387fa5 | 2014-01-03 16:54:28 -0800 | [diff] [blame] | 370 | #ifdef __cplusplus |
Mark Salyzyn | 8eaaac0 | 2016-09-27 11:18:29 -0700 | [diff] [blame] | 371 | // android_log_context C++ helpers |
| 372 | class android_log_event_context { |
| 373 | android_log_context ctx; |
| 374 | int ret; |
| 375 | |
| 376 | public: |
| 377 | explicit android_log_event_context(int tag) : ret(0) { |
| 378 | ctx = create_android_logger(tag); |
| 379 | } |
| 380 | explicit android_log_event_context(log_msg& log_msg) : ret(0) { |
| 381 | ctx = create_android_log_parser(log_msg.msg() + sizeof(uint32_t), |
| 382 | log_msg.entry.len - sizeof(uint32_t)); |
| 383 | } |
| 384 | ~android_log_event_context() { android_log_destroy(&ctx); } |
| 385 | |
| 386 | int close() { |
| 387 | int retval = android_log_destroy(&ctx); |
| 388 | if (retval < 0) ret = retval; |
| 389 | return retval; |
| 390 | } |
| 391 | |
| 392 | // To allow above C calls to use this class as parameter |
| 393 | operator android_log_context() const { return ctx; }; |
| 394 | |
| 395 | int error() const { return ret; } |
| 396 | |
| 397 | int begin() { |
| 398 | int retval = android_log_write_list_begin(ctx); |
| 399 | if (retval < 0) ret = retval; |
| 400 | return ret; |
| 401 | } |
| 402 | int end() { |
| 403 | int retval = android_log_write_list_end(ctx); |
| 404 | if (retval < 0) ret = retval; |
| 405 | return ret; |
| 406 | } |
| 407 | |
| 408 | android_log_event_context& operator <<(int32_t value) { |
| 409 | int retval = android_log_write_int32(ctx, value); |
| 410 | if (retval < 0) ret = retval; |
| 411 | return *this; |
| 412 | } |
| 413 | android_log_event_context& operator <<(uint32_t value) { |
| 414 | int retval = android_log_write_int32(ctx, value); |
| 415 | if (retval < 0) ret = retval; |
| 416 | return *this; |
| 417 | } |
| 418 | android_log_event_context& operator <<(int64_t value) { |
| 419 | int retval = android_log_write_int64(ctx, value); |
| 420 | if (retval < 0) ret = retval; |
| 421 | return *this; |
| 422 | } |
| 423 | android_log_event_context& operator <<(uint64_t value) { |
| 424 | int retval = android_log_write_int64(ctx, value); |
| 425 | if (retval < 0) ret = retval; |
| 426 | return *this; |
| 427 | } |
| 428 | android_log_event_context& operator <<(const char* value) { |
| 429 | int retval = android_log_write_string8(ctx, value); |
| 430 | if (retval < 0) ret = retval; |
| 431 | return *this; |
| 432 | } |
| 433 | android_log_event_context& operator <<(std::string& value) { |
| 434 | int retval = android_log_write_string8_len(ctx, |
| 435 | value.data(), |
| 436 | value.length()); |
| 437 | if (retval < 0) ret = retval; |
| 438 | return *this; |
| 439 | } |
| 440 | android_log_event_context& operator <<(float value) { |
| 441 | int retval = android_log_write_float32(ctx, value); |
| 442 | if (retval < 0) ret = retval; |
| 443 | return *this; |
| 444 | } |
| 445 | |
| 446 | int write(log_id_t id) { |
| 447 | int retval = android_log_write_list(ctx, id); |
| 448 | if (retval < 0) ret = retval; |
| 449 | return ret; |
| 450 | } |
| 451 | |
| 452 | android_log_list_element read() { return android_log_read_next(ctx); } |
| 453 | android_log_list_element peak() { return android_log_peek_next(ctx); } |
| 454 | |
| 455 | }; |
| 456 | #endif |
| 457 | |
| 458 | #ifdef __cplusplus |
Mark Salyzyn | f387fa5 | 2014-01-03 16:54:28 -0800 | [diff] [blame] | 459 | } |
| 460 | #endif |
Mark Salyzyn | 4295841 | 2013-11-22 10:50:27 -0800 | [diff] [blame] | 461 | |
Mark Salyzyn | 318bb72 | 2014-01-10 14:07:58 -0800 | [diff] [blame] | 462 | #endif /* _LIBS_LOG_LOGGER_H */ |