Kristian Lyngstøl wrote:
On 5/24/07, Mike Dransfield <[EMAIL PROTECTED]> wrote:
Attached is a quick patch which adds a logging framework to compiz.
I think it should be fairly self explanitory.
I think it should allow plugin writers to extend it for any purpose, but
I would appreciate any feedback or comments before going any further.
Looks good, we did something similar with Beryl which at least I
believe helped.
How about moving the proc to CompScreen? That way, I can wrap the
function in a hypothetical debug plug-in to print information about
the screen the log message occurred on (I have two).
It sounds like a good idea to have a debug plugin as well
as some more information in the messages from core.
I did not want the logging mechanism to know anything
about the message being logged, for this reason I have modified
the patches so that the wrapped function just takes a string
rather than a format/args combination.
I think that debugging can be acheived just by agreeing on a
debug log format. This way any debug logs will all be in the same
format and could be parsed at a later date with another app.
If we added a compiz event to the screenshot plugin then a debug
plugin could also do other things like recording the screenshot time
and date with the log. The debug plugin could wrap logMessage
and store the message in a different location and even upload it
later with the screenshots.
I have a small demo plugin which uses libnotify to show errors
to the user, it should be useful for plugin errors etc.
http://www.anykeysoftware.co.uk/compiz/plugins/notify.c
While plug-ins can obviously create their own macros, I also believe
it makes a lot of sense to have a few macros for this in compiz.h,
specially for core.
diff --git a/include/compiz.h b/include/compiz.h
index d50996f..0622c9b 100644
--- a/include/compiz.h
+++ b/include/compiz.h
@@ -26,7 +26,7 @@
#ifndef _COMPIZ_H
#define _COMPIZ_H
-#define ABIVERSION 20070507
+#define ABIVERSION 20070524
#include <stdio.h>
#include <sys/time.h>
@@ -309,6 +309,15 @@ typedef enum {
CompActionStateAutoGrab = 1 << 11
} CompActionState;
+typedef enum {
+ CompLogLevelFatal = 0,
+ CompLogLevelError,
+ CompLogLevelWarn,
+ CompLogLevelInfo,
+ CompLogLevelDebug
+
+} CompLogLevel;
+
typedef struct _CompKeyBinding {
int keycode;
unsigned int modifiers;
@@ -728,6 +737,11 @@ typedef void (*MatchExpHandlerChangedProc) (CompDisplay
*display);
typedef void (*MatchPropertyChangedProc) (CompDisplay *display,
CompWindow *window);
+typedef void (*LogMessageProc) (CompDisplay *d,
+ char *componentName,
+ CompLogLevel level,
+ char *message);
+
struct _CompDisplay {
Display *display;
CompScreen *screens;
@@ -925,9 +939,12 @@ struct _CompDisplay {
MatchExpHandlerChangedProc matchExpHandlerChanged;
MatchPropertyChangedProc matchPropertyChanged;
+ LogMessageProc logMessage;
+
CompPrivate *privates;
};
+
extern CompDisplay *compDisplays;
int
@@ -979,6 +996,15 @@ void
fileWatchRemoved (CompDisplay *display,
CompFileWatch *fileWatch);
+void
+compLogMessage (CompDisplay *d, char *componentName, CompLogLevel level, char
*format, ...);
+
+void
+logMessage (CompDisplay *d, char *componentName, CompLogLevel level, char
*message);
+
+char *
+logLevelToString (CompLogLevel level);
+
int
compCheckForError (Display *dpy);
diff --git a/src/display.c b/src/display.c
index 45ba4f0..616d8a3 100644
--- a/src/display.c
+++ b/src/display.c
@@ -2003,6 +2003,8 @@ addDisplay (char *name)
d->matchExpHandlerChanged = matchExpHandlerChanged;
d->matchPropertyChanged = matchPropertyChanged;
+ d->logMessage = logMessage;
+
d->supportedAtom = XInternAtom (dpy, "_NET_SUPPORTED", 0);
d->supportingWmCheckAtom = XInternAtom (dpy, "_NET_SUPPORTING_WM_CHECK",
0);
diff --git a/src/main.c b/src/main.c
index 477e3d0..3b9c397 100644
--- a/src/main.c
+++ b/src/main.c
@@ -120,6 +120,76 @@ usage (void)
programName);
}
+void
+compLogMessage (CompDisplay *d,
+ char *componentName,
+ CompLogLevel level,
+ char *format,
+ ...)
+{
+ va_list args;
+ char message[2048];
+
+ if (!d)
+ d = compDisplays;
+
+ va_start (args, format);
+
+ vsnprintf (message, 2048, format, args);
+
+ if (!d)
+ logMessage (d, componentName, level, message);
+ else
+ (*d->logMessage) (d, componentName, level, message);
+
+ va_end (args);
+}
+
+void
+logMessage (CompDisplay *d,
+ char *componentName,
+ CompLogLevel level,
+ char *message)
+{
+ char defaultMessage[2048];
+
+ snprintf (defaultMessage, 2048, "%s (%s): %s",
+ programName, componentName, message);
+
+ fprintf (stderr, defaultMessage);
+ fprintf (stderr, "\n");
+}
+
+char *
+logLevelToString (CompLogLevel level)
+{
+ char *logStr;
+
+ switch (level)
+ {
+ case CompLogLevelFatal:
+ logStr = strdup ("Fatal");
+ break;
+ case CompLogLevelError:
+ logStr = strdup ("Error");
+ break;
+ case CompLogLevelWarn:
+ logStr = strdup ("Warn");
+ break;
+ case CompLogLevelInfo:
+ logStr = strdup ("Info");
+ break;
+ case CompLogLevelDebug:
+ logStr = strdup ("Debug");
+ break;
+ default:
+ logStr = strdup ("Unknown");
+ break;
+ }
+
+ return logStr;
+}
+
static void
signalHandler (int sig)
{
@@ -227,6 +297,8 @@ main (int argc, char **argv)
programArgc = argc;
programArgv = argv;
+ compDisplays = NULL;
+
signal (SIGHUP, signalHandler);
signal (SIGCHLD, signalHandler);
signal (SIGINT, signalHandler);
@@ -329,7 +401,8 @@ main (int argc, char **argv)
}
else if (*argv[i] == '-')
{
- fprintf (stderr, "%s: Unknown option '%s'\n", programName, argv[i]);
+ compLogMessage (NULL, "core", CompLogLevelWarn,
+ "Unknown option '%s'\n", argv[i]);
}
else
{
diff --git a/src/plugin.c b/src/plugin.c
index e4e49be..2f26e2e 100644
--- a/src/plugin.c
+++ b/src/plugin.c
@@ -499,7 +499,7 @@ loadPlugin (char *name)
if (status)
return p;
- fprintf (stderr, "%s: Couldn't load plugin '%s'\n", programName, name);
+ compLogMessage (NULL, "core", CompLogLevelError, "Couldn't load plugin
'%s'", name);
return 0;
}
_______________________________________________
compiz mailing list
compiz@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/compiz