Skip to content

Commit

Permalink
Fremantle 35-gmessages.patch
Browse files Browse the repository at this point in the history
  • Loading branch information
muks authored and smokku committed Apr 11, 2012
1 parent 5f4b431 commit 64f7133
Show file tree
Hide file tree
Showing 2 changed files with 162 additions and 0 deletions.
145 changes: 145 additions & 0 deletions glib/gmessages.c
Expand Up @@ -46,6 +46,8 @@
* flow, only to give a perhaps-helpful warning before giving up.
*/

#define MAEMO_SYSLOG_ENABLED /* Maemo builds will temporary use syslog for logging */

#include "config.h"

#include <stdlib.h>
Expand Down Expand Up @@ -211,6 +213,10 @@
* Since: 2.6
*/

#ifdef MAEMO_SYSLOG_ENABLED
#include <syslog.h>
#endif

/* --- structures --- */
typedef struct _GLogDomain GLogDomain;
typedef struct _GLogHandler GLogHandler;
Expand Down Expand Up @@ -1076,6 +1082,7 @@ _g_log_fallback_handler (const gchar *log_domain,
write_string (fd, message);
}

#ifndef MAEMO_SYSLOG_ENABLED
static void
escape_string (GString *string)
{
Expand Down Expand Up @@ -1135,6 +1142,7 @@ escape_string (GString *string)
p = g_utf8_next_char (p);
}
}
#endif /* not MAEMO_SYSLOG_ENABLED */

/**
* g_log_default_handler:
Expand Down Expand Up @@ -1173,6 +1181,141 @@ escape_string (GString *string)
* %G_LOG_LEVEL_WARNING and %G_LOG_LEVEL_MESSAGE. stdout is used for
* the rest.
*/
#ifdef MAEMO_SYSLOG_ENABLED
/* That is a syslog version of default log handler. */
/* It shall be used only in case that MAEMO_SYSLOG_ENABLED switched on. */

#define IS_EMPTY_STRING(s) (NULL == (s) || 0 == *(s))

#define GLIB_PREFIX "GLIB"
#define DEFAULT_DOMAIN "default"
#define DEFAULT_MESSAGE "(NULL) message"

static unsigned int G_LOG_OUTPUT_LEVEL;

enum
{
G_LOG_OUTPUT_LEVEL_MIN = 0,
G_LOG_OUTPUT_LEVEL_CRITICAL,
G_LOG_OUTPUT_LEVEL_WARNING,
G_LOG_OUTPUT_LEVEL_MAX
};

#define G_LOG_OUTPUT_LEVEL_DEF G_LOG_OUTPUT_LEVEL_MAX

void g_log_default_handler (
const gchar* log_domain,
GLogLevelFlags log_level,
const gchar* message,
gpointer unused_data
)
{
/* This value will be switched to TRUE when log facility is initialized */
static gboolean initialized = FALSE;

/* This call only variables */
const gchar* alert = (log_level & ALERT_LEVELS ? " ** " : " ");
const gchar* aborting = (log_level & G_LOG_FLAG_FATAL ? "\naborting..." : "");

const gchar* prefix;
int priority;

gchar *output_level;
int level;

/* Check first that logging facility is initialized */
if ( !initialized )
{
openlog(NULL, LOG_PERROR|LOG_PID, LOG_USER);
initialized = !initialized;

G_LOG_OUTPUT_LEVEL = G_LOG_OUTPUT_LEVEL_DEF;

output_level = getenv("G_LOG_OUTPUT_LEVEL");
if (output_level)
{
level = atoi(output_level);

if (level >= G_LOG_OUTPUT_LEVEL_MIN &&
level <= G_LOG_OUTPUT_LEVEL_MAX)
{
G_LOG_OUTPUT_LEVEL = level;
}
}
}

/* Validate log domain */
if ( IS_EMPTY_STRING(log_domain) )
log_domain = DEFAULT_DOMAIN;

/* Check log message for validity */
if ( IS_EMPTY_STRING(message) )
message = DEFAULT_MESSAGE;


/* no logging on minimal output level */
if (G_LOG_OUTPUT_LEVEL == G_LOG_OUTPUT_LEVEL_MIN)
{
return;
}

/* if warning|message and level critical, return */
if ((log_level & G_LOG_LEVEL_MASK) >= G_LOG_LEVEL_WARNING)
{
if (G_LOG_OUTPUT_LEVEL == (G_LOG_OUTPUT_LEVEL_CRITICAL))
{
return;
}
}

/* if message and level warning, return */
if ((log_level & G_LOG_LEVEL_MASK) >= G_LOG_LEVEL_MESSAGE)
{
if (G_LOG_OUTPUT_LEVEL <= (G_LOG_OUTPUT_LEVEL_WARNING))
{
return;
}
}

/* Process the message prefix and priority */
switch (log_level & G_LOG_LEVEL_MASK)
{
case G_LOG_FLAG_FATAL:
prefix = "FATAL";
priority = LOG_EMERG;
break;
case G_LOG_LEVEL_ERROR:
prefix = "ERROR";
priority = LOG_ERR;
break;
case G_LOG_LEVEL_CRITICAL:
prefix = "CRITICAL";
priority = LOG_CRIT;
break;
case G_LOG_LEVEL_WARNING:
prefix = "WARNING";
priority = LOG_WARNING;
break;
case G_LOG_LEVEL_MESSAGE:
prefix = "MESSAGE";
priority = LOG_NOTICE;
break;
case G_LOG_LEVEL_INFO:
prefix = "INFO";
priority = LOG_INFO;
break;
default:
prefix = "DEBUG";
priority = LOG_DEBUG;
break;
} /* switch log_level */

/* Now prining the message to syslog */
syslog(priority, "%s %s%s%s - %s%s", GLIB_PREFIX, prefix, alert, log_domain, message, aborting);
} /* g_log_default_handler -- syslog version */

#else /* not MAEMO_SYSLOG_ENABLED -- we will use standart stderr logging */

void
g_log_default_handler (const gchar *log_domain,
GLogLevelFlags log_level,
Expand Down Expand Up @@ -1270,6 +1413,8 @@ g_log_default_handler (const gchar *log_domain,
*
* Returns: the old print handler
*/
#endif /* if MAEMO_SYSLOG_ENABLED */

GPrintFunc
g_set_print_handler (GPrintFunc func)
{
Expand Down
17 changes: 17 additions & 0 deletions glib/gmessages.h
Expand Up @@ -152,9 +152,13 @@ void g_assert_warning (const char *log_domain,
#define g_warning(...) g_log (G_LOG_DOMAIN, \
G_LOG_LEVEL_WARNING, \
__VA_ARGS__)
#ifndef G_DEBUG_DISABLE
#define g_debug(...) g_log (G_LOG_DOMAIN, \
G_LOG_LEVEL_DEBUG, \
__VA_ARGS__)
#else
#define g_debug(...)
#endif
#elif defined(G_HAVE_GNUC_VARARGS)
#define g_error(format...) G_STMT_START { \
g_log (G_LOG_DOMAIN, \
Expand All @@ -172,9 +176,13 @@ void g_assert_warning (const char *log_domain,
#define g_warning(format...) g_log (G_LOG_DOMAIN, \
G_LOG_LEVEL_WARNING, \
format)
#ifndef G_DEBUG_DISABLE
#define g_debug(format...) g_log (G_LOG_DOMAIN, \
G_LOG_LEVEL_DEBUG, \
format)
#else
#define g_debug(...)
#endif
#else /* no varargs macros */
static void
g_error (const gchar *format,
Expand Down Expand Up @@ -214,6 +222,7 @@ g_warning (const gchar *format,
g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, format, args);
va_end (args);
}
#ifndef G_DEBUG_DISABLE
static void
g_debug (const gchar *format,
...)
Expand All @@ -223,6 +232,14 @@ g_debug (const gchar *format,
g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, format, args);
va_end (args);
}
#else
static void
g_debug (const gchar *format,
...)
{
; /* debug logging disabled */
}
#endif
#endif /* !__GNUC__ */

/**
Expand Down

0 comments on commit 64f7133

Please sign in to comment.