{
return -1;
}
+static int __write_to_log_kernel(log_id_t log_id, log_priority prio, const char *tag, const char *msg)
+{
+ ssize_t ret;
+ int log_fd;
+ struct iovec vec[3];
+
+ if (log_id < LOG_ID_APPS) {
+ if(prio < g_dlog_level) {
+ return 0;
+ }
+ } else if (LOG_ID_MAX <= log_id) {
+ return 0;
+ }
+ if (log_id < LOG_ID_MAX)
+ log_fd = log_fds[log_id];
+ else
+ return -1; // for TC
+
+ if (!tag)
+ tag = "";
+
+ if (!msg)
+ return -1;
+
+ vec[0].iov_base = (unsigned char *) &prio;
+ vec[0].iov_len = 1;
+ vec[1].iov_base = (void *) tag;
+ vec[1].iov_len = strlen(tag) + 1;
+ vec[2].iov_base = (void *) msg;
+ vec[2].iov_len = strlen(msg) + 1;
+
+ ret = writev(log_fd, vec, 3);
+
+ return ret;
+}
+static char dlog_pri_to_char (log_priority pri)
+{
+ switch (pri) {
+ case DLOG_VERBOSE: return 'V';
+ case DLOG_DEBUG: return 'D';
+ case DLOG_INFO: return 'I';
+ case DLOG_WARN: return 'W';
+ case DLOG_ERROR: return 'E';
+ case DLOG_FATAL: return 'F';
+ case DLOG_SILENT: return 'S';
+
+ case DLOG_DEFAULT:
+ case DLOG_UNKNOWN:
+ default:
+ return '?';
+ }
+}
#ifdef SD_JOURNAL_SUPPORT
static int dlog_pri_to_journal_pri(log_priority prio)
{
}
static int __write_to_log_sd_journal_print(log_id_t log_id, log_priority prio, const char *tag, const char *msg)
{
- sd_journal_print(dlog_pri_to_journal_pri(prio), "%s %s", tag, msg);
- return 1;
-}
-#else
-static int __write_to_log_kernel(log_id_t log_id, log_priority prio, const char *tag, const char *msg)
-{
ssize_t ret;
int log_fd;
- struct iovec vec[3];
if (log_id < LOG_ID_APPS) {
if(prio < g_dlog_level) {
if (log_id < LOG_ID_MAX)
log_fd = log_fds[log_id];
else
- return -1; // for TC
-
- if (!tag)
- tag = "";
-
- vec[0].iov_base = (unsigned char *) &prio;
- vec[0].iov_len = 1;
- vec[1].iov_base = (void *) tag;
- vec[1].iov_len = strlen(tag) + 1;
- vec[2].iov_base = (void *) msg;
- vec[2].iov_len = strlen(msg) + 1;
-
- ret = writev(log_fd, vec, 3);
-
- return ret;
+ return -1;
+ return sd_journal_print(dlog_pri_to_journal_pri(prio), "%c %s: %s",dlog_pri_to_char(prio), tag, msg);
}
#endif
void init_dlog_level(void)
static int __dlog_init(log_id_t log_id, log_priority prio, const char *tag, const char *msg)
{
pthread_mutex_lock(&log_init_lock);
-#ifdef SD_JOURNAL_SUPPORT
- write_to_log = __write_to_log_sd_journal_print;
-#else
// get filtering info
// open device
if (write_to_log == __dlog_init) {
if (log_fds[LOG_ID_MAIN] < 0 || log_fds[LOG_ID_RADIO] < 0) {
fprintf(stderr, "open log dev is failed\n");
write_to_log = __write_to_log_null;
- } else
+ } else {
+#ifdef SD_JOURNAL_SUPPORT
+ write_to_log = __write_to_log_sd_journal_print;
+#else
write_to_log = __write_to_log_kernel;
+#endif
+ }
if (log_fds[LOG_ID_SYSTEM] < 0)
log_fds[LOG_ID_SYSTEM] = log_fds[LOG_ID_MAIN];
if (log_fds[LOG_ID_APPS] < 0)
log_fds[LOG_ID_APPS] = log_fds[LOG_ID_MAIN];
}
-#endif
pthread_mutex_unlock(&log_init_lock);
return write_to_log(log_id, prio, tag, msg);
}
static void setup_output()
{
- if (g_output_filename == NULL) {
- g_outfd = STDOUT_FILENO;
-
- } else {
- struct stat statbuf;
-
- g_outfd = open_logfile (g_output_filename);
+ if (g_output_filename == NULL) {
+ g_outfd = STDOUT_FILENO;
- if (g_outfd < 0) {
- perror ("couldn't open output file");
- exit(-1);
- }
+ } else {
+ struct stat statbuf;
- fstat(g_outfd, &statbuf);
+ g_outfd = open_logfile (g_output_filename);
- g_out_byte_count = statbuf.st_size;
- }
+ if (g_outfd < 0) {
+ perror ("couldn't open output file");
+ exit(-1);
+ }
+ if (fstat(g_outfd, &statbuf) == -1)
+ g_out_byte_count = 0;
+ else
+ g_out_byte_count = statbuf.st_size;
+ }
}
static int set_log_format(const char * formatString)
Name: dlog
Summary: Logging service
Version: 0.4.1
-Release: 1
+Release: 2
Group: System/Libraries
License: Apache License
Source0: %{name}-%{version}.tar.gz
Source101: packaging/dlog-main.service
Source102: packaging/dlog-radio.service
Source103: packaging/tizen-debug-level.service
-BuildRequires: pkgconfig(systemd)
+BuildRequires: pkgconfig(libsystemd-journal)
Requires(post): /sbin/ldconfig
Requires(post): /usr/bin/systemctl
Requires(post): /usr/bin/vconftool
+Requires(post): coreutils
Requires(postun): /sbin/ldconfig
Requires(postun): /usr/bin/systemctl
Requires(preun): /usr/bin/systemctl