logging: make libi3 use verboselog()/errorlog(), provide it in each caller

While this is a bit ugly, it makes the log messages end up where they
are supposed to: in the shmlog/stdout in case of i3 and on stdout in
case of utilities such as i3-input
This commit is contained in:
Michael Stapelberg 2012-08-13 13:27:00 +02:00
parent 6c9bf84d4e
commit 2896ae8057
6 changed files with 88 additions and 7 deletions

View File

@ -84,6 +84,26 @@ Display *dpy;
char *rewrite_binding(const char *bindingline);
static void finish();
/*
* Having verboselog() and errorlog() is necessary when using libi3.
*
*/
void verboselog(char *fmt, ...) {
va_list args;
va_start(args, fmt);
vfprintf(stdout, fmt, args);
va_end(args);
}
void errorlog(char *fmt, ...) {
va_list args;
va_start(args, fmt);
vfprintf(stderr, fmt, args);
va_end(args);
}
/*
* This function resolves ~ in pathnames.
* It may resolve wildcards in the first part of the path, but if no match

View File

@ -56,6 +56,26 @@ xcb_window_t root;
xcb_connection_t *conn;
xcb_screen_t *root_screen;
/*
* Having verboselog() and errorlog() is necessary when using libi3.
*
*/
void verboselog(char *fmt, ...) {
va_list args;
va_start(args, fmt);
vfprintf(stdout, fmt, args);
va_end(args);
}
void errorlog(char *fmt, ...) {
va_list args;
va_start(args, fmt);
vfprintf(stderr, fmt, args);
va_end(args);
}
/*
* Concats the glyphs (either UCS-2 or UTF-8) to a single string, suitable for
* rendering it (UCS-2) or sending it to i3 (UTF-8).

View File

@ -56,6 +56,26 @@ xcb_window_t root;
xcb_connection_t *conn;
xcb_screen_t *root_screen;
/*
* Having verboselog() and errorlog() is necessary when using libi3.
*
*/
void verboselog(char *fmt, ...) {
va_list args;
va_start(args, fmt);
vfprintf(stdout, fmt, args);
va_end(args);
}
void errorlog(char *fmt, ...) {
va_list args;
va_start(args, fmt);
vfprintf(stderr, fmt, args);
va_end(args);
}
/*
* Starts the given application by passing it through a shell. We use double fork
* to avoid zombie processes. As the started applications parent exits (immediately),

View File

@ -2,7 +2,7 @@
* vim:ts=4:sw=4:expandtab
*
* i3bar - an xcb-based status- and ws-bar for i3
* © 2010-2011 Axel Wagner and contributors (see also: LICENSE)
* © 2010-2012 Axel Wagner and contributors (see also: LICENSE)
*
*/
#include <stdio.h>
@ -17,6 +17,26 @@
#include "common.h"
/*
* Having verboselog() and errorlog() is necessary when using libi3.
*
*/
void verboselog(char *fmt, ...) {
va_list args;
va_start(args, fmt);
vfprintf(stdout, fmt, args);
va_end(args);
}
void errorlog(char *fmt, ...) {
va_list args;
va_start(args, fmt);
vfprintf(stderr, fmt, args);
va_end(args);
}
/*
* Glob path, i.e. expand ~
*

View File

@ -69,10 +69,12 @@ struct Font {
/* Since this file also gets included by utilities which dont use the i3 log
* infrastructure, we define a fallback. */
#if !defined(LOG)
#define LOG(fmt, ...) fprintf(stdout, "[libi3] " __FILE__ " " fmt, ##__VA_ARGS__)
void verboselog(char *fmt, ...);
#define LOG(fmt, ...) verboselog("[libi3] " __FILE__ " " fmt, ##__VA_ARGS__)
#endif
#if !defined(ELOG)
#define ELOG(fmt, ...) fprintf(stderr, "[libi3] ERROR: " fmt, ##__VA_ARGS__)
void errorlog(char *fmt, ...);
#define ELOG(fmt, ...) errorlog("[libi3] ERROR: " fmt, ##__VA_ARGS__)
#endif
/**

View File

@ -38,13 +38,12 @@ static double pango_font_blue;
static bool load_pango_font(i3Font *font, const char *desc) {
/* Load the font description */
font->specific.pango_desc = pango_font_description_from_string(desc);
if (!font->specific.pango_desc)
{
if (!font->specific.pango_desc) {
ELOG("Could not open font %s with Pango, fallback to X font.\n", desc);
return false;
}
LOG("Using Pango font %s, size %d",
LOG("Using Pango font %s, size %d\n",
pango_font_description_get_family(font->specific.pango_desc),
pango_font_description_get_size(font->specific.pango_desc)
);
@ -186,7 +185,7 @@ i3Font load_font(const char *pattern, const bool fallback) {
}
}
LOG("Using X font %s", pattern);
LOG("Using X font %s\n", pattern);
/* Get information (height/name) for this font */
if (!(font.specific.xcb.info = xcb_query_font_reply(conn, info_cookie, NULL)))