2013-11-23 02:50:27 +08:00
|
|
|
/*
|
|
|
|
**
|
2014-01-03 05:52:29 +08:00
|
|
|
** Copyright 2007-2014, The Android Open Source Project
|
2009-03-04 11:32:55 +08:00
|
|
|
**
|
|
|
|
** This file is dual licensed. It may be redistributed and/or modified
|
|
|
|
** under the terms of the Apache 2.0 License OR version 2 of the GNU
|
|
|
|
** General Public License.
|
|
|
|
*/
|
|
|
|
|
2014-01-11 06:07:58 +08:00
|
|
|
#ifndef _LIBS_LOG_LOGGER_H
|
|
|
|
#define _LIBS_LOG_LOGGER_H
|
2009-03-04 11:32:55 +08:00
|
|
|
|
|
|
|
#include <stdint.h>
|
2013-11-23 02:50:27 +08:00
|
|
|
#include <log/log.h>
|
2014-02-15 08:05:05 +08:00
|
|
|
#include <log/log_read.h>
|
2013-11-23 02:50:27 +08:00
|
|
|
|
2014-01-04 08:54:28 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
2009-03-04 11:32:55 +08:00
|
|
|
|
2012-03-23 05:28:16 +08:00
|
|
|
/*
|
|
|
|
* The userspace structure for version 1 of the logger_entry ABI.
|
|
|
|
* This structure is returned to userspace by the kernel logger
|
|
|
|
* driver unless an upgrade to a newer ABI version is requested.
|
|
|
|
*/
|
2009-03-04 11:32:55 +08:00
|
|
|
struct logger_entry {
|
|
|
|
uint16_t len; /* length of the payload */
|
|
|
|
uint16_t __pad; /* no matter what, we get 2 bytes of padding */
|
|
|
|
int32_t pid; /* generating process's pid */
|
|
|
|
int32_t tid; /* generating process's tid */
|
|
|
|
int32_t sec; /* seconds since Epoch */
|
|
|
|
int32_t nsec; /* nanoseconds */
|
|
|
|
char msg[0]; /* the entry's payload */
|
2014-03-05 23:41:49 +08:00
|
|
|
} __attribute__((__packed__));
|
2009-03-04 11:32:55 +08:00
|
|
|
|
2012-03-23 05:28:16 +08:00
|
|
|
/*
|
|
|
|
* The userspace structure for version 2 of the logger_entry ABI.
|
|
|
|
* This structure is returned to userspace if ioctl(LOGGER_SET_VERSION)
|
2014-02-27 01:50:16 +08:00
|
|
|
* is called with version==2; or used with the user space log daemon.
|
2012-03-23 05:28:16 +08:00
|
|
|
*/
|
|
|
|
struct logger_entry_v2 {
|
|
|
|
uint16_t len; /* length of the payload */
|
|
|
|
uint16_t hdr_size; /* sizeof(struct logger_entry_v2) */
|
|
|
|
int32_t pid; /* generating process's pid */
|
|
|
|
int32_t tid; /* generating process's tid */
|
|
|
|
int32_t sec; /* seconds since Epoch */
|
|
|
|
int32_t nsec; /* nanoseconds */
|
|
|
|
uint32_t euid; /* effective UID of logger */
|
|
|
|
char msg[0]; /* the entry's payload */
|
2014-03-05 23:41:49 +08:00
|
|
|
} __attribute__((__packed__));
|
2012-03-23 05:28:16 +08:00
|
|
|
|
2014-02-27 01:50:16 +08:00
|
|
|
struct logger_entry_v3 {
|
|
|
|
uint16_t len; /* length of the payload */
|
2014-03-05 23:41:49 +08:00
|
|
|
uint16_t hdr_size; /* sizeof(struct logger_entry_v3) */
|
2014-02-27 01:50:16 +08:00
|
|
|
int32_t pid; /* generating process's pid */
|
|
|
|
int32_t tid; /* generating process's tid */
|
|
|
|
int32_t sec; /* seconds since Epoch */
|
|
|
|
int32_t nsec; /* nanoseconds */
|
|
|
|
uint32_t lid; /* log id of the payload */
|
|
|
|
char msg[0]; /* the entry's payload */
|
2014-03-05 23:41:49 +08:00
|
|
|
} __attribute__((__packed__));
|
2014-02-27 01:50:16 +08:00
|
|
|
|
2012-03-23 05:28:16 +08:00
|
|
|
/*
|
|
|
|
* The maximum size of the log entry payload that can be
|
2014-05-23 07:08:52 +08:00
|
|
|
* written to the logger. An attempt to write more than
|
|
|
|
* this amount will result in a truncated log entry.
|
2012-03-23 05:28:16 +08:00
|
|
|
*/
|
|
|
|
#define LOGGER_ENTRY_MAX_PAYLOAD 4076
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The maximum size of a log entry which can be read from the
|
|
|
|
* kernel logger driver. An attempt to read less than this amount
|
|
|
|
* may result in read() returning EINVAL.
|
|
|
|
*/
|
|
|
|
#define LOGGER_ENTRY_MAX_LEN (5*1024)
|
2009-03-04 11:32:55 +08:00
|
|
|
|
2013-11-23 02:50:27 +08:00
|
|
|
#define NS_PER_SEC 1000000000ULL
|
|
|
|
|
|
|
|
struct log_msg {
|
|
|
|
union {
|
|
|
|
unsigned char buf[LOGGER_ENTRY_MAX_LEN + 1];
|
2014-02-21 06:59:07 +08:00
|
|
|
struct logger_entry_v3 entry;
|
2014-02-27 01:50:16 +08:00
|
|
|
struct logger_entry_v3 entry_v3;
|
2013-11-23 02:50:27 +08:00
|
|
|
struct logger_entry_v2 entry_v2;
|
|
|
|
struct logger_entry entry_v1;
|
|
|
|
} __attribute__((aligned(4)));
|
|
|
|
#ifdef __cplusplus
|
2014-01-11 06:07:58 +08:00
|
|
|
/* Matching log_time operators */
|
|
|
|
bool operator== (const log_msg &T) const
|
2013-11-23 02:50:27 +08:00
|
|
|
{
|
|
|
|
return (entry.sec == T.entry.sec) && (entry.nsec == T.entry.nsec);
|
|
|
|
}
|
2014-01-11 06:07:58 +08:00
|
|
|
bool operator!= (const log_msg &T) const
|
2013-11-23 02:50:27 +08:00
|
|
|
{
|
|
|
|
return !(*this == T);
|
|
|
|
}
|
2014-01-11 06:07:58 +08:00
|
|
|
bool operator< (const log_msg &T) const
|
2013-11-23 02:50:27 +08:00
|
|
|
{
|
|
|
|
return (entry.sec < T.entry.sec)
|
|
|
|
|| ((entry.sec == T.entry.sec)
|
|
|
|
&& (entry.nsec < T.entry.nsec));
|
|
|
|
}
|
2014-01-11 06:07:58 +08:00
|
|
|
bool operator>= (const log_msg &T) const
|
2013-11-23 02:50:27 +08:00
|
|
|
{
|
|
|
|
return !(*this < T);
|
|
|
|
}
|
2014-01-11 06:07:58 +08:00
|
|
|
bool operator> (const log_msg &T) const
|
2013-11-23 02:50:27 +08:00
|
|
|
{
|
|
|
|
return (entry.sec > T.entry.sec)
|
|
|
|
|| ((entry.sec == T.entry.sec)
|
|
|
|
&& (entry.nsec > T.entry.nsec));
|
|
|
|
}
|
2014-01-11 06:07:58 +08:00
|
|
|
bool operator<= (const log_msg &T) const
|
2013-11-23 02:50:27 +08:00
|
|
|
{
|
|
|
|
return !(*this > T);
|
|
|
|
}
|
2014-02-27 01:50:16 +08:00
|
|
|
uint64_t nsec() const
|
2013-11-23 02:50:27 +08:00
|
|
|
{
|
|
|
|
return static_cast<uint64_t>(entry.sec) * NS_PER_SEC + entry.nsec;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* packet methods */
|
2014-02-27 01:50:16 +08:00
|
|
|
log_id_t id()
|
2013-11-23 02:50:27 +08:00
|
|
|
{
|
2014-02-21 06:59:07 +08:00
|
|
|
return (log_id_t) entry.lid;
|
2013-11-23 02:50:27 +08:00
|
|
|
}
|
2014-02-27 01:50:16 +08:00
|
|
|
char *msg()
|
2013-11-23 02:50:27 +08:00
|
|
|
{
|
|
|
|
return entry.hdr_size ? (char *) buf + entry.hdr_size : entry_v1.msg;
|
|
|
|
}
|
2014-02-27 01:50:16 +08:00
|
|
|
unsigned int len()
|
2013-11-23 02:50:27 +08:00
|
|
|
{
|
|
|
|
return (entry.hdr_size ? entry.hdr_size : sizeof(entry_v1)) + entry.len;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
struct logger;
|
|
|
|
|
|
|
|
log_id_t android_logger_get_id(struct logger *logger);
|
|
|
|
|
|
|
|
int android_logger_clear(struct logger *logger);
|
2014-02-12 04:29:31 +08:00
|
|
|
long android_logger_get_log_size(struct logger *logger);
|
|
|
|
int android_logger_set_log_size(struct logger *logger, unsigned long size);
|
|
|
|
long android_logger_get_log_readable_size(struct logger *logger);
|
2013-11-23 02:50:27 +08:00
|
|
|
int android_logger_get_log_version(struct logger *logger);
|
|
|
|
|
|
|
|
struct logger_list;
|
|
|
|
|
2014-02-07 06:48:50 +08:00
|
|
|
ssize_t android_logger_get_statistics(struct logger_list *logger_list,
|
|
|
|
char *buf, size_t len);
|
2014-02-12 04:29:31 +08:00
|
|
|
ssize_t android_logger_get_prune_list(struct logger_list *logger_list,
|
|
|
|
char *buf, size_t len);
|
|
|
|
int android_logger_set_prune_list(struct logger_list *logger_list,
|
|
|
|
char *buf, size_t len);
|
2014-02-07 06:48:50 +08:00
|
|
|
|
2015-01-27 02:46:44 +08:00
|
|
|
#define ANDROID_LOG_RDONLY O_RDONLY
|
|
|
|
#define ANDROID_LOG_WRONLY O_WRONLY
|
|
|
|
#define ANDROID_LOG_RDWR O_RDWR
|
|
|
|
#define ANDROID_LOG_ACCMODE O_ACCMODE
|
|
|
|
#define ANDROID_LOG_NONBLOCK O_NONBLOCK
|
2014-12-16 01:51:39 +08:00
|
|
|
#define ANDROID_LOG_PSTORE 0x80000000
|
2015-01-27 02:46:44 +08:00
|
|
|
|
2013-11-23 02:50:27 +08:00
|
|
|
struct logger_list *android_logger_list_alloc(int mode,
|
|
|
|
unsigned int tail,
|
|
|
|
pid_t pid);
|
2014-02-15 08:05:05 +08:00
|
|
|
struct logger_list *android_logger_list_alloc_time(int mode,
|
|
|
|
log_time start,
|
|
|
|
pid_t pid);
|
2013-11-23 02:50:27 +08:00
|
|
|
void android_logger_list_free(struct logger_list *logger_list);
|
|
|
|
/* In the purest sense, the following two are orthogonal interfaces */
|
|
|
|
int android_logger_list_read(struct logger_list *logger_list,
|
|
|
|
struct log_msg *log_msg);
|
|
|
|
|
|
|
|
/* Multiple log_id_t opens */
|
|
|
|
struct logger *android_logger_open(struct logger_list *logger_list,
|
|
|
|
log_id_t id);
|
|
|
|
#define android_logger_close android_logger_free
|
|
|
|
/* Single log_id_t open */
|
|
|
|
struct logger_list *android_logger_list_open(log_id_t id,
|
|
|
|
int mode,
|
|
|
|
unsigned int tail,
|
|
|
|
pid_t pid);
|
|
|
|
#define android_logger_list_close android_logger_list_free
|
|
|
|
|
|
|
|
/*
|
|
|
|
* log_id_t helpers
|
|
|
|
*/
|
|
|
|
log_id_t android_name_to_log_id(const char *logName);
|
|
|
|
const char *android_log_id_to_name(log_id_t log_id);
|
|
|
|
|
2014-01-04 08:54:28 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
2013-11-23 02:50:27 +08:00
|
|
|
|
2014-01-11 06:07:58 +08:00
|
|
|
#endif /* _LIBS_LOG_LOGGER_H */
|