Exemplo n.º 1
0
void
oio_log_syslog(const gchar *log_domain, GLogLevelFlags log_level,
		const gchar *message, gpointer user_data UNUSED)
{
	if (!glvl_allowed(log_level))
		return;

	GString *gstr = g_string_new("");

	g_string_append_printf(gstr, "%d %04X", getpid(), oio_log_current_thread_id());

	if (LOG_LOCAL1 == get_facility(log_domain)) {
		g_string_append(gstr, " access ");
		g_string_append(gstr, glvl_to_str(log_level));
	}
	else {
		if (!log_domain || !*log_domain)
			log_domain = "-";
		g_string_append(gstr, " log ");
		g_string_append(gstr, glvl_to_str(log_level));
		g_string_append_c(gstr, ' ');
		g_string_append(gstr, log_domain);
	}

	g_string_append_c(gstr, ' ');

	_append_message(gstr, message);

	syslog(get_facility(log_domain)|glvl_to_lvl(log_level), "%s", gstr->str);
	g_string_free(gstr, TRUE);
}
Exemplo n.º 2
0
static void
_logger_stderr(const gchar *log_domain, GLogLevelFlags log_level,
		const gchar *message, gpointer user_data)
{
	static guint longest_prefix = 38;
	GString *gstr = g_string_sized_new(256);
	(void) user_data;

	g_string_append_printf(gstr, "%"G_GINT64_FORMAT" %d %04X ",
			g_get_monotonic_time () / G_TIME_SPAN_MILLISECOND,
			getpid(), oio_log_current_thread_id());

	if (!log_domain || !*log_domain)
		log_domain = "-";

	if (LOG_LOCAL1 == get_facility(log_domain)) {
		g_string_append_printf(gstr, "acc %s ", glvl_to_str(log_level));
	} else {
		g_string_append_printf(gstr, "log %s ", glvl_to_str(log_level));

		/* print the domain */
		if (!(oio_log_flags & LOG_FLAG_TRIM_DOMAIN))
			g_string_append(gstr, log_domain);
		else {
			const gchar *p = log_domain;
			while (p && *p) {
				g_string_append_c(gstr, *p);
				p = strchr(p, '.');
				if (p) {
					g_string_append_c(gstr, '.');
					p ++;
				}
			}
		}
	}

	/* prefix done, print a separator */
	if (oio_log_flags & LOG_FLAG_COLUMNIZE) {
		longest_prefix = MAX(gstr->len+1,longest_prefix);
		do {
			g_string_append_c(gstr, ' ');
		} while (gstr->len < longest_prefix);
	}
	else
		g_string_append_c(gstr, ' ');

	/* now append the message */
	_append_message(gstr, message);
	g_string_append_c(gstr, '\n');

	if (oio_log_flags & LOG_FLAG_PURIFY)
		_purify(gstr->str);

	/* send the buffer */
	fwrite(gstr->str, gstr->len, 1, stderr);
	g_string_free(gstr, TRUE);
}