mirror of
https://github.com/awesomeWM/awesome
synced 2024-11-16 07:47:22 +01:00
Add timestamps to messages on stderr (#602)
Closes https://github.com/awesomeWM/awesome/pull/606. Fixes https://github.com/awesomeWM/awesome/issues/602. Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
parent
fc8c91c075
commit
720cd879f3
7 changed files with 43 additions and 10 deletions
|
@ -28,6 +28,22 @@
|
|||
#include <limits.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <time.h>
|
||||
|
||||
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");
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
2
luaa.h
2
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);
|
||||
|
|
Loading…
Reference in a new issue