* lib: refactor mu-log a bit
This commit is contained in:
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)
|
do{if (MU_LOG->_color_stderr) fputs ((C),stderr);} while (0)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
log_write (const char* domain, GLogLevelFlags level,
|
log_write_fd (GLogLevelFlags level, const gchar *msg)
|
||||||
const gchar *msg)
|
|
||||||
{
|
{
|
||||||
time_t now;
|
time_t now;
|
||||||
ssize_t len;
|
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];
|
char buf [768], timebuf [22];
|
||||||
|
|
||||||
g_return_if_fail (MU_LOG);
|
|
||||||
|
|
||||||
/* get the time/date string */
|
/* get the time/date string */
|
||||||
now = time(NULL);
|
now = time(NULL);
|
||||||
strftime (timebuf, sizeof(timebuf), "%Y-%m-%d %H:%M:%S",
|
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,
|
len = snprintf (buf, sizeof(buf), "%s [%s] %s\n", timebuf,
|
||||||
pfx(level), msg);
|
pfx(level), msg);
|
||||||
|
|
||||||
|
|
||||||
if (write (MU_LOG->_fd, buf, (size_t)len) < 0)
|
if (write (MU_LOG->_fd, buf, (size_t)len) < 0)
|
||||||
fprintf (stderr, "%s: failed to write to log: %s\n",
|
fprintf (stderr, "%s: failed to write to log: %s\n",
|
||||||
__FUNCTION__, strerror(errno));
|
__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 ?
|
mu = MU_LOG->_opts & MU_LOG_OPTIONS_NEWLINE ?
|
||||||
"\nmu: " : "mu: ";
|
"\nmu: " : "mu: ";
|
||||||
@ -294,3 +299,13 @@ log_write (const char* domain, GLogLevelFlags level,
|
|||||||
color_stderr_maybe (MU_COLOR_DEFAULT);
|
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);
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user