mirror of https://github.com/djcb/mu.git
* lib: refactor mu-log a bit
This commit is contained in:
parent
ac12d0c8aa
commit
2db1606a36
27
lib/mu-log.c
27
lib/mu-log.c
|
@ -245,19 +245,16 @@ pfx (GLogLevelFlags level)
|
|||
do{if (MU_LOG->_color_stderr) fputs ((C),stderr);} while (0)
|
||||
|
||||
|
||||
|
||||
static void
|
||||
log_write (const char* domain, GLogLevelFlags level,
|
||||
const gchar *msg)
|
||||
log_write_fd (GLogLevelFlags level, const gchar *msg)
|
||||
{
|
||||
time_t now;
|
||||
ssize_t len;
|
||||
const char *mu;
|
||||
|
||||
/* log lines will be truncated at 768-1 chars */
|
||||
/* truncate at 768-1 chars */
|
||||
char buf [768], timebuf [22];
|
||||
|
||||
g_return_if_fail (MU_LOG);
|
||||
|
||||
/* get the time/date string */
|
||||
now = time(NULL);
|
||||
strftime (timebuf, sizeof(timebuf), "%Y-%m-%d %H:%M:%S",
|
||||
|
@ -267,9 +264,17 @@ log_write (const char* domain, GLogLevelFlags level,
|
|||
len = snprintf (buf, sizeof(buf), "%s [%s] %s\n", timebuf,
|
||||
pfx(level), msg);
|
||||
|
||||
|
||||
if (write (MU_LOG->_fd, buf, (size_t)len) < 0)
|
||||
fprintf (stderr, "%s: failed to write to log: %s\n",
|
||||
__FUNCTION__, strerror(errno));
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
log_write_stdout_stderr (GLogLevelFlags level, const gchar *msg)
|
||||
{
|
||||
const char *mu;
|
||||
|
||||
mu = MU_LOG->_opts & MU_LOG_OPTIONS_NEWLINE ?
|
||||
"\nmu: " : "mu: ";
|
||||
|
@ -294,3 +299,13 @@ log_write (const char* domain, GLogLevelFlags level,
|
|||
color_stderr_maybe (MU_COLOR_DEFAULT);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
log_write (const char* domain, GLogLevelFlags level, const gchar *msg)
|
||||
{
|
||||
g_return_if_fail (MU_LOG);
|
||||
|
||||
log_write_fd (level, msg);
|
||||
log_write_stdout_stderr (level, msg);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue