--- /dev/null
+#ifndef __LABWC_LOG_H
+#define __LABWC_LOG_H
+
+/**
+ * info - print info message
+ */
+void info(const char *msg, ...);
+
+/**
+ * warn - print warning
+ */
+void warn(const char *err, ...);
+
+#endif /* __LABWC_LOG_H */
#include "labwc.h"
#include "common/spawn.h"
+#include "common/log.h"
#include <strings.h>
} else if (!strcasecmp(keybind->action, "debug-views")) {
dbg_show_views(server);
} else {
- fprintf(stderr, "warn: action (%s) not supported\n",
- keybind->action);
+ warn("action (%s) not supported", keybind->action);
}
}
#include <glib.h>
#include "common/dir.h"
+#include "common/log.h"
struct dir {
const char *prefix;
/* handle /etc/xdg... */
ctx->build_path_fn(ctx, NULL, d.path);
if (debug)
- fprintf(stderr, "DEBUG: %s\n", ctx->buf);
+ info("%s", ctx->buf);
if (isdir(ctx->buf))
return ctx->buf;
} else {
for (gchar **p = prefixes; *p; p++) {
ctx->build_path_fn(ctx, *p, d.path);
if (debug)
- fprintf(stderr, "DEBUG: %s\n",
- ctx->buf);
+ info("%s", ctx->buf);
if (isdir(ctx->buf))
return ctx->buf;
}
--- /dev/null
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <string.h>
+
+#define LABWC_COLOR_YELLOW "\033[0;33m"
+#define LABWC_COLOR_RED "\033[0;31m"
+#define LABWC_COLOR_RESET "\033[0m"
+
+void info(const char *msg, ...)
+{
+ va_list params;
+ fprintf(stderr, LABWC_COLOR_YELLOW);
+ fprintf(stderr, "[labwc] info: ");
+ va_start(params, msg);
+ vfprintf(stderr, msg, params);
+ va_end(params);
+ fprintf(stderr, LABWC_COLOR_RESET);
+ fprintf(stderr, "\n");
+}
+
+void warn(const char *err, ...)
+{
+ va_list params;
+ fprintf(stderr, LABWC_COLOR_RED);
+ fprintf(stderr, "[labwc] warning: ");
+ va_start(params, err);
+ vfprintf(stderr, err, params);
+ va_end(params);
+ fprintf(stderr, LABWC_COLOR_RESET);
+ fprintf(stderr, "\n");
+}
'dir.c',
'font.c',
'grab-file.c',
+ 'log.c',
'spawn.c',
)
#include "config/keybind.h"
#include "config/rcxml.h"
+#include "common/log.h"
static uint32_t parse_modifier(const char *symname)
{
xkb_keysym_t sym = xkb_keysym_from_name(
symname, XKB_KEYSYM_NO_FLAGS);
if (sym == XKB_KEY_NoSymbol) {
- fprintf(stderr, "unknown keybind (%s)\n",
- symname);
+ warn("unknown keybind (%s)", symname);
free(k);
k = NULL;
break;
#include "common/dir.h"
#include "common/bug-on.h"
#include "common/font.h"
+#include "common/log.h"
static bool in_keybind = false;
static bool is_attribute = false;
{
xmlDoc *d = xmlParseMemory(b->buf, b->len);
if (!d) {
- fprintf(stderr, "fatal: xmlParseMemory()\n");
+ warn("xmlParseMemory()");
exit(EXIT_FAILURE);
}
xml_tree_walk(xmlDocGetRootElement(d));
struct keybind *k = keybind_add(binding);
if (k)
k->action = strdup(action);
- fprintf(stderr, "binding: %s: %s\n", binding, action);
+ info("binding %s: %s", binding, action);
}
static void set_title_height(void)
static void post_processing(void)
{
if (!wl_list_length(&rc.keybinds)) {
- fprintf(stderr, "info: loading default key bindings\n");
+ info("loading default key bindings");
bind("A-Escape", "Exit");
bind("A-Tab", "NextWindow");
bind("A-F3", "Execute");
* unit tests.
*/
rcxml_path(rcxml, sizeof(rcxml), filename);
- fprintf(stderr, "info: read config file (%s)\n", rcxml);
+ info("reading config file (%s)", rcxml);
stream = fopen(rcxml, "r");
if (!stream) {
- fprintf(stderr, "warn: cannot read '%s'\n", rcxml);
+ warn("cannot read (%s)", rcxml);
goto out;
}
buf_init(&b);
#include "labwc.h"
+#include "common/log.h"
static void keyboard_handle_modifiers(struct wl_listener *listener, void *data)
{
} else if (event->state == WLR_KEY_PRESSED) {
/* cycle to next */
server->cycle_view = next_toplevel(server->cycle_view);
- fprintf(stderr, "cycle_view=%p\n",
- (void *)server->cycle_view);
+ info("cycle_view=%p", (void *)server->cycle_view);
return;
}
}
#include "theme/theme.h"
#include "common/dir.h"
+#include "common/log.h"
static int hex_to_dec(char c)
{
char themerc[4096];
snprintf(themerc, sizeof(themerc), "%s/themerc", theme_dir(theme_name));
- fprintf(stderr, "info: read themerc (%s)\n", themerc);
+ info("reading themerc (%s)", themerc);
stream = fopen(themerc, "r");
if (!stream) {
- fprintf(stderr, "warn: cannot read (%s)\n", themerc);
+ warn("cannot read (%s)", themerc);
return;
}
while (getline(&line, &len, stream) != -1) {
#include "labwc.h"
+#include "common/log.h"
int xwl_nr_parents(struct view *view)
{
int i = 0;
if (!s) {
- fprintf(stderr, "warn: (%s) no xwayland surface\n", __func__);
+ warn("(%s) no xwayland surface\n", __func__);
return -1;
}
while (s->parent) {
'../src/common/dir.c',
'../src/common/buf.c',
'../src/common/font.c',
+ '../src/common/log.c',
),
dependencies: labwc_deps,
include_directories: [labwc_inc],