diff --git a/common/util.c b/common/util.c index 518da2e8..267fd559 100644 --- a/common/util.c +++ b/common/util.c @@ -28,6 +28,22 @@ #include #include #include +#include + +const char * +a_current_time_str(void) +{ + static char buffer[25]; + time_t now; + struct tm tm; + + time(&now); + localtime_r(&now, &tm); + if (!strftime(buffer, sizeof(buffer), "%Y-%m-%d %T ", &tm)) + buffer[0] = '\0'; + + return buffer; +} /** Print error and exit with EXIT_FAILURE code. */ @@ -37,7 +53,7 @@ _fatal(int line, const char *fct, const char *fmt, ...) va_list ap; va_start(ap, fmt); - fprintf(stderr, "E: awesome: %s:%d: ", fct, line); + fprintf(stderr, "%sE: awesome: %s:%d: ", a_current_time_str(), fct, line); vfprintf(stderr, fmt, ap); va_end(ap); fprintf(stderr, "\n"); @@ -51,7 +67,7 @@ _warn(int line, const char *fct, const char *fmt, ...) { va_list ap; va_start(ap, fmt); - fprintf(stderr, "W: awesome: %s:%d: ", fct, line); + fprintf(stderr, "%sW: awesome: %s:%d: ", a_current_time_str(), fct, line); vfprintf(stderr, fmt, ap); va_end(ap); fprintf(stderr, "\n"); diff --git a/common/util.h b/common/util.h index af3c4d84..eaa9a58d 100644 --- a/common/util.h +++ b/common/util.h @@ -319,6 +319,8 @@ void _fatal(int, const char *, const char *, ...) void _warn(int, const char *, const char *, ...) __attribute__ ((format(printf, 3, 4))); +const char *a_current_time_str(void); + void a_exec(const char *); #endif diff --git a/lib/awful/util.lua b/lib/awful/util.lua index 665953f1..0b633cfb 100644 --- a/lib/awful/util.lua +++ b/lib/awful/util.lua @@ -28,6 +28,7 @@ local capi = awesome = awesome, mouse = mouse } +local gears_debug = require("gears.debug") local floor = math.floor local util = {} @@ -48,11 +49,11 @@ function util.deprecate(see) -- Get function name/desc from caller. local info = debug.getinfo(2, "n") local funcname = info.name or "?" - io.stderr:write("W: awful: function " .. funcname .. " is deprecated") + local msg = "awful: function " .. funcname .. " is deprecated" if see then - io.stderr:write(", see " .. see) + msg = msg .. ", see " .. see end - io.stderr:write(".\n" .. tb .. "\n") + gears_debug.print_warning(msg .. ".\n" .. tb) end --- Get a valid color for Pango markup diff --git a/lib/beautiful/init.lua b/lib/beautiful/init.lua index 0a1fc7cd..e3aee501 100644 --- a/lib/beautiful/init.lua +++ b/lib/beautiful/init.lua @@ -26,6 +26,7 @@ local capi = screen = screen, awesome = awesome } +local gears_debug = require("gears.debug") local xresources = require("beautiful.xresources") @@ -134,7 +135,7 @@ function beautiful.init(config) end if not success then - return print("E: beautiful: error loading theme file " .. theme) + return gears_debug.print_error("beautiful: error loading theme file " .. theme) elseif theme then -- expand '~' if homedir then @@ -145,10 +146,10 @@ function beautiful.init(config) if theme.font then set_font(theme.font) end else - return print("E: beautiful: error loading theme file " .. config) + return gears_debug.print_error("beautiful: error loading theme file " .. config) end else - return print("E: beautiful: error loading theme: no theme specified") + return gears_debug.print_error("beautiful: error loading theme: no theme specified") end end diff --git a/lib/beautiful/xresources.lua b/lib/beautiful/xresources.lua index 1fb098ca..44ffb236 100644 --- a/lib/beautiful/xresources.lua +++ b/lib/beautiful/xresources.lua @@ -11,6 +11,7 @@ local print = print local awesome = awesome local round = require("awful.util").round +local gears_debug = require("gears.debug") local xresources = {} @@ -53,7 +54,7 @@ function xresources.get_current_theme() for _, key in ipairs(keys) do colors[key] = awesome.xrdb_get_value("", key) if not colors[key] then - print("W: beautiful: can't get colorscheme from xrdb (using fallback).") + gears_debug.print_warning("beautiful: can't get colorscheme from xrdb (using fallback).") return fallback end end diff --git a/lib/gears/debug.lua b/lib/gears/debug.lua index f36a8089..af323e2e 100644 --- a/lib/gears/debug.lua +++ b/lib/gears/debug.lua @@ -64,6 +64,18 @@ function debug.dump(data, tag, depth) print(debug.dump_return(data, tag, depth)) end +-- Print an warning message +-- @tparam string message The warning message to print +function debug.print_warning(message) + io.stderr:write(os.date("%Y-%m-%d %T W: ") .. tostring(message) .. "\n") +end + +-- Print an error message +-- @tparam string message The error message to print +function debug.print_error(message) + io.stderr:write(os.date("%Y-%m-%d %T E: ") .. tostring(message) .. "\n") +end + return debug -- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/luaa.h b/luaa.h index d098761f..cf519cdd 100644 --- a/luaa.h +++ b/luaa.h @@ -50,7 +50,7 @@ luaA_warn(lua_State *L, const char *fmt, ...) { va_list ap; luaL_where(L, 1); - fprintf(stderr, "%sW: ", lua_tostring(L, -1)); + fprintf(stderr, "%s%sW: ", a_current_time_str(), lua_tostring(L, -1)); lua_pop(L, 1); va_start(ap, fmt); vfprintf(stderr, fmt, ap);