static muse_core_log_t *g_muse_core_log = NULL;
static gboolean _muse_core_log_pid_is_valid(pid_t pid);
+static void _muse_core_log_latest_msgs(void);
static void _muse_core_log_pid_info(pid_t pid);
static void _muse_core_log_cmdline(pid_t pid);
static void _muse_core_log_process_info(pid_t pid);
static void _muse_core_log_write_buffer(const void *buf, size_t len);
static void _muse_core_log_attributes(const char *msg, ...);
static void _muse_core_log_monitor(char *msg);
+static void _muse_core_log_cache_latest_msg(char *msg);
static void _muse_core_log_fatal(char *msg);
static void _muse_core_log_set_msg(char *msg);
static char *_muse_core_log_get_msg(void);
return TRUE;
}
+static void _muse_core_log_latest_msgs(void)
+{
+ g_return_if_fail(g_muse_core_log);
+ int idx, start_idx;
+
+ g_mutex_lock(&g_muse_core_log->log_lock);
+
+ if (muse_core_ipc_fd_is_valid(g_muse_core_log->log_fd)) {
+ start_idx = (g_muse_core_log->currnt_index + 1) % MUSE_LOG_MSG_NUM;
+
+ for (idx = start_idx; idx < MUSE_LOG_MSG_NUM; idx++) {
+ if (write(g_muse_core_log->log_fd, g_muse_core_log->latest_msgs[idx], strlen(g_muse_core_log->latest_msgs[idx])) == WRITE_FAIL)
+ LOGE("fail to write sequentially the latest message by first step");
+ else if (write(g_muse_core_log->log_fd, "\n", 1) == WRITE_FAIL)
+ LOGE("fail to write new line character");
+ }
+
+ for (idx = 0; idx < start_idx; idx++) {
+ if (write(g_muse_core_log->log_fd, g_muse_core_log->latest_msgs[idx], strlen(g_muse_core_log->latest_msgs[idx])) == WRITE_FAIL)
+ LOGE("fail to write sequentially the latest message by second step");
+ else if (write(g_muse_core_log->log_fd, "\n", 1) == WRITE_FAIL)
+ LOGE("fail to write new line character");
+ }
+ }
+
+ g_mutex_unlock(&g_muse_core_log->log_lock);
+}
+
static void _muse_core_log_pid_info(pid_t pid)
{
char client_buf[MAX_ERROR_MSG_LEN];
snprintf(client_buf, sizeof(client_buf), "[PID] %d", (int)pid);
if (write(g_muse_core_log->log_fd, client_buf, strlen(client_buf)) == WRITE_FAIL)
LOGE("There was an error writing client pid to logfile");
- else if (write(g_muse_core_log->log_fd, "\0", 1) != WRITE_FAIL)
+ else if (write(g_muse_core_log->log_fd, "\n", 1) != WRITE_FAIL)
LOGE("%s", client_buf);
}
if (write(g_muse_core_log->log_fd, client_buf, strlen(client_buf)) == WRITE_FAIL)
LOGE("There was an error writing client name to logfile");
- else if (write(g_muse_core_log->log_fd, "\0", 1) != WRITE_FAIL)
+ else if (write(g_muse_core_log->log_fd, "\n", 1) != WRITE_FAIL)
LOGE("[Process Name] %s", client_buf);
fclose(fp);
if (fp) {
if (write(g_muse_core_log->log_fd, client_buf, strlen(client_buf)) == WRITE_FAIL)
LOGE("muse-server %d writing command to logfile", (int)pid);
- else if (write(g_muse_core_log->log_fd, "\0", 1) == WRITE_FAIL)
- LOGE("Fail to write process command");
+ else if (write(g_muse_core_log->log_fd, "\n", 1) == WRITE_FAIL)
+ LOGE("fail to write process command");
while (fgets(client_buf, MAX_ERROR_MSG_LEN, fp)) {
if (write(g_muse_core_log->log_fd, client_buf, strlen(client_buf)) == WRITE_FAIL)
- LOGE("Fail to write command info to logfile");
+ LOGE("fail to write command info to logfile");
}
if (pclose(fp) == -1)
- LOGE("Fail to pclose");
+ LOGE("fail to pclose");
}
}
memset(&info, 0, sizeof(info));
if (dladdr((const void *) ptr, &info) && info.dli_sname)
- _muse_core_log_monitor((char *)info.dli_sname);
+ _muse_core_log_cache_latest_msg((char *)info.dli_sname);
else
LOGE("fail to log api name");
}
snprintf(client_buf, sizeof(client_buf), "[The latest called api name] %s [The latest message] %s", (char *)info.dli_sname, _muse_core_log_get_msg());
if (write(g_muse_core_log->log_fd, client_buf, strlen(client_buf)) == WRITE_FAIL)
LOGE("There was an error writing client's latest called api to logfile");
- else if (write(g_muse_core_log->log_fd, "\0", 1) != WRITE_FAIL)
+ else if (write(g_muse_core_log->log_fd, "\n", 1) != WRITE_FAIL)
LOGE("%s", client_buf);
}
}
}
if (g_muse_core_log) {
+ /* latest api */
+ _muse_core_log_latest_msgs();
+
/* pid */
_muse_core_log_pid_info(pid);
g_return_if_fail(g_muse_core_log);
memset(g_muse_core_log->buf, 0, MUSE_MSG_MAX_LENGTH + 1);
g_muse_core_log->size = 0;
- memset(g_muse_core_log->cache, 0, MUSE_LOG_MSG_CACHE_MAX_LENGTH + 1);
+ memset(g_muse_core_log->cache, 0, MUSE_MSG_MAX_LENGTH + 1);
g_muse_core_log->log = log;
g_muse_core_log->log_attr = log_attr;
g_muse_core_log->fatal = fatal;
g_muse_core_log->log_api_name = log_api_name;
g_muse_core_log->free = free;
g_mutex_init(&g_muse_core_log->log_lock);
+ g_muse_core_log->currnt_index = 0;
}
static void
g_mutex_lock(&g_muse_core_log->log_lock);
if (muse_core_ipc_fd_is_valid(g_muse_core_log->log_fd)) {
- if (strlen(g_muse_core_log->cache) + strlen(msg) < MUSE_LOG_MSG_CACHE_MAX_LENGTH) {
+ if (strlen(g_muse_core_log->cache) + strlen(msg) < MUSE_MSG_MAX_LENGTH) {
_muse_core_log_write_buffer(msg, strlen(msg));
} else {
if (write(g_muse_core_log->log_fd, g_muse_core_log->cache, strlen(g_muse_core_log->cache)) != WRITE_FAIL) {
- memset(g_muse_core_log->cache, 0, MUSE_LOG_MSG_CACHE_MAX_LENGTH + 1);
+ memset(g_muse_core_log->cache, 0, MUSE_MSG_MAX_LENGTH + 1);
_muse_core_log_write_buffer(msg, strlen(msg));
}
}
g_mutex_unlock(&g_muse_core_log->log_lock);
}
+static void _muse_core_log_cache_latest_msg(char *msg)
+{
+ g_return_if_fail(msg);
+ g_return_if_fail(g_muse_core_log);
+
+ struct timeval tv;
+ char time_buf[MUSE_LOG_LEN];
+
+ g_mutex_lock(&g_muse_core_log->log_lock);
+
+ gettimeofday(&tv, NULL);
+ strftime(time_buf, sizeof(time_buf), "%m-%d %H:%M:%S", localtime(&(tv.tv_sec)));
+ snprintf(g_muse_core_log->latest_msgs[g_muse_core_log->currnt_index], MUSE_LOG_MSG_LEN, "%s.%03ld %s ", time_buf, tv.tv_usec / 1000, msg);
+
+ g_muse_core_log->currnt_index = (g_muse_core_log->currnt_index + 1) % MUSE_LOG_MSG_NUM;
+
+ g_mutex_unlock(&g_muse_core_log->log_lock);
+}
+
static void _muse_core_log_fatal(char *msg)
{
if (!msg) {
LOGE("There was an error writing to logfile [%d] %s", str_len, g_muse_core_log->cache);
}
- memset(g_muse_core_log->cache, 0, MUSE_LOG_MSG_CACHE_MAX_LENGTH + 1);
+ memset(g_muse_core_log->cache, 0, MUSE_MSG_MAX_LENGTH + 1);
}
muse_core_log_t *muse_core_log_get_instance(void)