struct log_config;
-extern int (*write_to_log)(log_id_t, log_priority, const char *tag, const char *msg);
+extern int (*write_to_log)(log_id_t, log_priority, const char *tag, const char *msg, struct timespec *tp_mono);
extern void (*destroy_backend)();
extern pthread_rwlock_t log_limiter_lock;
* @return Returns the number of bytes written on success and a negative error value on error.
* @see __dlog_init_backend
*/
-int (*write_to_log)(log_id_t log_id, log_priority prio, const char *tag, const char *msg) = NULL;
+int (*write_to_log)(log_id_t log_id, log_priority prio, const char *tag, const char *msg, struct timespec *tp_mono) = NULL;
void (*destroy_backend)();
pthread_rwlock_t log_limiter_lock = PTHREAD_RWLOCK_INITIALIZER;
if (!should_log) {
return DLOG_ERROR_NOT_PERMITTED;
} else if (should_log < 0) {
+ struct timespec tp;
+ int result = clock_gettime(CLOCK_MONOTONIC, &tp);
+ if (result < 0)
+ return DLOG_ERROR_NOT_PERMITTED;
write_to_log(log_id, prio, tag,
- "Your log has been blocked due to limit of log lines per minute.");
+ "Your log has been blocked due to limit of log lines per minute.", &tp);
return DLOG_ERROR_NOT_PERMITTED;
}
}
char buf[LOG_MAX_PAYLOAD_SIZE];
vsnprintf(buf, sizeof buf, fmt, ap);
- return write_to_log(log_id, prio, tag, buf);
+
+ struct timespec tp;
+ int result = clock_gettime(CLOCK_MONOTONIC, &tp);
+ if (result < 0)
+ return DLOG_ERROR_NONE;
+
+ return write_to_log(log_id, prio, tag, buf, &tp);
}
static int __write_to_log(log_id_t log_id, int prio, const char *tag, const char *fmt, va_list ap, bool check_should_log, bool secure_log)
* @param[in] msg The contents of the message.
* @return Number of bytes written, or negative errno
*/
-static int __write_to_log_android(log_id_t log_id, log_priority prio, const char *tag, const char *msg)
+static int __write_to_log_android(log_id_t log_id, log_priority prio, const char *tag, const char *msg, struct timespec *tp_mono)
{
ssize_t ret;
int log_fd;
#ifdef USE_ANDROID_MONOTONIC
struct iovec vec[4];
-
- struct timespec ts;
struct android_logger_footer alf;
- clock_gettime(CLOCK_MONOTONIC, &ts);
alf.magic = ANDROID_LOGGER_FOOTER_MAGIC;
- alf.sec_sent_mono = ts.tv_sec;
- alf.nsec_sent_mono = ts.tv_nsec;
+ alf.sec_sent_mono = tp_mono->tv_sec;
+ alf.nsec_sent_mono = tp_mono->tv_nsec;
vec[3].iov_base = (void *) &alf;
vec[3].iov_len = sizeof alf;
static char log_pipe_path[LOG_ID_MAX][PATH_MAX];
static int wait_pipe_ms = DEFAULT_WAIT_PIPE_MS;
-static int __write_to_log_pipe(log_id_t log_id, log_priority prio, const char *tag, const char *msg);
+static int __write_to_log_pipe(log_id_t log_id, log_priority prio, const char *tag, const char *msg, struct timespec *tp_mono);
static pthread_rwlock_t log_pipe_lock = PTHREAD_RWLOCK_INITIALIZER;
* @param[in] msg The contents of the message.
* @return Number of bytes written, or negative errno
*/
-static int __write_to_log_pipe(log_id_t log_id, log_priority prio, const char *tag, const char *msg)
+static int __write_to_log_pipe(log_id_t log_id, log_priority prio, const char *tag, const char *msg, struct timespec *tp_mono)
{
ssize_t ret = 0;
char buf[LOG_MAX_PAYLOAD_SIZE + sizeof(struct pipe_logger_entry)];
return DLOG_ERROR_INVALID_PARAMETER;
create_pipe_message(buf, prio, tag, msg);
- set_pipe_message_sent_timestamp((struct pipe_logger_entry *) buf, NULL, NULL);
+ set_pipe_message_sent_timestamp((struct pipe_logger_entry *) buf, tp_mono, NULL);
if (!pthread_rwlock_rdlock(&log_pipe_lock)) {
ret = _write_to_log_pipe_critical_section(log_id, buf);
assert(write_to_log);
assert(destroy_backend);
-#define F(B, P, M) assert(write_to_log(B, P, "tag", M) == DLOG_ERROR_INVALID_PARAMETER)
+ struct timespec tp;
+ int result = clock_gettime(CLOCK_MONOTONIC, &tp);
+ if (result < 0)
+ return EXIT_FAILURE;
+
+#define F(B, P, M) assert(write_to_log(B, P, "tag", M, &tp) == DLOG_ERROR_INVALID_PARAMETER)
F(LOG_ID_INVALID, DLOG_ERROR , "xx");
F(LOG_ID_MAX , DLOG_ERROR , "xx");
F(LOG_ID_MAIN , DLOG_UNKNOWN , "xx");
writev_called = false;
writev_ret = -1;
errno_to_set = i + 10;
- assert(write_to_log(i, i + 3, "tag", LONG_TEXTS[i]) == -(i + 10));
+ assert(write_to_log(i, i + 3, "tag", LONG_TEXTS[i], &tp) == -(i + 10));
assert(writev_called);
}
assert(write_to_log);
assert(destroy_backend);
+ struct timespec tp;
+ int result = clock_gettime(CLOCK_MONOTONIC, &tp);
+ if (result < 0)
+ return EXIT_FAILURE;
used_tag = "tag";
for (int i = 0; i < 4; ++i) {
writev_called = false;
writev_ret = i + 20;
used_msg = LONG_TEXTS[i];
- assert(write_to_log(i, i + 3, "tag", LONG_TEXTS[i]) == i + 20);
+ assert(write_to_log(i, i + 3, "tag", LONG_TEXTS[i], &tp) == i + 20);
assert(writev_called);
}
used_tag = "";
used_msg = LONG_TEXTS[0];
writev_ret = 1234;
- assert(write_to_log(0, 3, NULL, LONG_TEXTS[0]) == 1234);
+ assert(write_to_log(0, 3, NULL, LONG_TEXTS[0], &tp) == 1234);
destroy_backend();
assert(closed + 1 == LOG_ID_MAX);
#include <queued_entry.h>
#endif /* USE_ANDROID_MONOTONIC */
-int (*write_to_log)(log_id_t, log_priority, const char *tag, const char *msg) = NULL;
+int (*write_to_log)(log_id_t, log_priority, const char *tag, const char *msg, struct timespec *tp_mono) = NULL;
void (*destroy_backend)() = NULL;
extern void __dlog_init_android(const struct log_config *conf);
destroyed = true;
}
-int wtl_android(log_id_t buf_id, log_priority pri, const char *tag, const char *msg) { return 45835705; }
-int wtl_pipe(log_id_t buf_id, log_priority pri, const char *tag, const char *msg) { return 0xDECC16; }
+int wtl_android(log_id_t buf_id, log_priority pri, const char *tag, const char *msg, struct timespec *tp_mono) { return 45835705; }
+int wtl_pipe(log_id_t buf_id, log_priority pri, const char *tag, const char *msg, struct timespec *tp_mono) { return 0xDECC16; }
void __dlog_init_pipe(const struct log_config *conf) { write_to_log = wtl_pipe; }
void __dlog_init_android(const struct log_config *conf)
#include <libdlog.h>
#include <logconfig.h>
-int wtl(log_id_t buf_id, log_priority pri, const char *tag, const char *msg) { return 0xABCD; }
+int wtl(log_id_t buf_id, log_priority pri, const char *tag, const char *msg, struct timespec *tp_mono) { return 0xABCD; }
void __dlog_init_pipe(const struct log_config *conf) { write_to_log = wtl; }
int __wrap_log_config_read(struct log_config *config)