*/
typedef enum {
gras_log_priority_none = 0,
- gras_log_priority_debug = 1,
- gras_log_priority_verbose = 2,
- gras_log_priority_info = 3,
- gras_log_priority_warning = 4,
- gras_log_priority_error = 5,
- gras_log_priority_critical = 6,
+ gras_log_priority_trace = 1,
+ gras_log_priority_debug = 2,
+ gras_log_priority_verbose = 3,
+ gras_log_priority_info = 4,
+ gras_log_priority_warning = 5,
+ gras_log_priority_error = 6,
+ gras_log_priority_critical = 7,
- gras_log_priority_infinite = 7,
+ gras_log_priority_infinite = 8,
gras_log_priority_uninitialized = -1
} gras_log_priority_t;
+/**
+ * NLOG:
+ *
+ * All logging facilities are disabled at compilation time
+ */
+
+
/**
* GRAS_LOG_STATIC_THRESHOLD:
*
* All logging with priority < GRAS_LOG_STATIC_THRESHOLD is disabled at
* compile time, i.e., compiled out.
*/
+#ifdef NLOG
+# define GRAS_LOG_STATIC_THRESHOLD gras_log_priority_infinite
+#else
+
#ifndef GRAS_LOG_STATIC_THRESHOLD
# define GRAS_LOG_STATIC_THRESHOLD gras_log_priority_none
-#endif
-
+#endif
+#endif /* !defined(NLOG) */
/* Transforms a category name to a global variable name. */
#define _GRAS_LOGV(cat) _GRAS_LOG_CONCAT(_gras_this_log_category_does_not_exist__, cat)
*
* Defines a new subcategory of the parent.
*/
+//#ifndef NLOG
#define GRAS_LOG_NEW_SUBCATEGORY(catName, parent) \
extern gras_log_category_t _GRAS_LOGV(parent); \
gras_log_category_t _GRAS_LOGV(catName) = { \
#catName, gras_log_priority_uninitialized, 1, \
0, 1 \
};
+//#else /* No logging at all, please */
+//#define GRAS_LOG_NEW_SUBCATEGORY(catName,parent)
+//#endif
/**
* GRAS_LOG_NEW_CATEGORY:
* Indicates which category is the default one.
*/
-#ifdef GRAS_LOG_MAYDAY /* debuging the logs themselves */
+#if defined(GRAS_LOG_MAYDAY) /*|| defined (NLOG) * turning logging off */
# define GRAS_LOG_DEFAULT_CATEGORY(cname)
#else
# define GRAS_LOG_DEFAULT_CATEGORY(cname) \
* Do NOT access any members of this structure directly.
*/
struct gras_log_category_s {
- gras_log_category_t *parent;
- gras_log_category_t *firstChild, *nextSibling;
- const char *name;
- int threshold;
- int isThreshInherited;
- gras_log_appender_t *appender;
- int willLogToParent;
+ gras_log_category_t *parent;
+/*@null@*/ gras_log_category_t *firstChild;
+/*@null@*/ gras_log_category_t *nextSibling;
+ const char *name;
+ int threshold;
+ int isThreshInherited;
+/*@null@*/ gras_log_appender_t *appender;
+ int willLogToParent;
// TODO: Formats?
};
struct gras_log_appender_s {
void (*do_append) (gras_log_appender_t* thisLogAppender,
- gras_log_event_t* event);
+ gras_log_event_t* event, const char *fmt);
void *appender_data;
};
const char* fileName;
const char* functionName;
int lineNum;
- const char* fmt;
va_list ap;
};
// Functions that you shouldn't call.
extern void _gras_log_event_log(gras_log_event_t*ev,
- ...);
+ const char *fmt,
+ ...)
+#ifdef __GNUC__
+ __attribute__ ((format (printf, 2, 3)))
+#endif
+;
+
extern int _gras_log_cat_init(gras_log_priority_t priority,
gras_log_category_t* category);
* Setting the LogEvent's valist member is done inside _log_logEvent.
*/
-#define _GRAS_LOG_PRE(catv, priority, fmt) do { \
+#define _GRAS_LOG_PRE(catv, priority) do { \
if (_GRAS_LOG_ISENABLEDV(catv, priority)) { \
gras_log_event_t _log_ev = \
- {&(catv),priority,__FILE__,__FUNCTION__,__LINE__,fmt}; \
+ {&(catv),priority,__FILE__,__FUNCTION__,__LINE__}; \
_gras_log_event_log(&_log_ev
+
#define _GRAS_LOG_POST \
); \
} } while(0)
# define CLOG7(c, p, f,a1,a2,a3,a4,a5,a6,a7) fprintf(stderr,"%s:%d:" f "\n",__FILE__,__LINE__,a1,a2,a3,a4,a5,a6,a7)
# define CLOG8(c, p, f,a1,a2,a3,a4,a5,a6,a7,a8) fprintf(stderr,"%s:%d:" f "\n",__FILE__,__LINE__,a1,a2,a3,a4,a5,a6,a7,a8)
#else
-# define CLOG0(c, p, f) _GRAS_LOG_PRE(_GRAS_LOGV(c),p,f) _GRAS_LOG_POST
-# define CLOG1(c, p, f,a1) _GRAS_LOG_PRE(_GRAS_LOGV(c),p,f) ,a1 _GRAS_LOG_POST
-# define CLOG2(c, p, f,a1,a2) _GRAS_LOG_PRE(_GRAS_LOGV(c),p,f) ,a1,a2 _GRAS_LOG_POST
-# define CLOG3(c, p, f,a1,a2,a3) _GRAS_LOG_PRE(_GRAS_LOGV(c),p,f) ,a1,a2,a3 _GRAS_LOG_POST
-# define CLOG4(c, p, f,a1,a2,a3,a4) _GRAS_LOG_PRE(_GRAS_LOGV(c),p,f) ,a1,a2,a3,a4 _GRAS_LOG_POST
-# define CLOG5(c, p, f,a1,a2,a3,a4,a5) _GRAS_LOG_PRE(_GRAS_LOGV(c),p,f) ,a1,a2,a3,a4,a5 _GRAS_LOG_POST
-# define CLOG6(c, p, f,a1,a2,a3,a4,a5,a6) _GRAS_LOG_PRE(_GRAS_LOGV(c),p,f) ,a1,a2,a3,a4,a5,a6 _GRAS_LOG_POST
-# define CLOG7(c, p, f,a1,a2,a3,a4,a5,a6,a7) _GRAS_LOG_PRE(_GRAS_LOGV(c),p,f) ,a1,a2,a3,a4,a5,a6,a7 _GRAS_LOG_POST
-# define CLOG8(c, p, f,a1,a2,a3,a4,a5,a6,a7,a8) _GRAS_LOG_PRE(_GRAS_LOGV(c),p,f) ,a1,a2,a3,a4,a5,a6,a7,a8 _GRAS_LOG_POST
+# define CLOG0(c, p, f) _GRAS_LOG_PRE(_GRAS_LOGV(c),p) ,f _GRAS_LOG_POST
+# define CLOG1(c, p, f,a1) _GRAS_LOG_PRE(_GRAS_LOGV(c),p) ,f,a1 _GRAS_LOG_POST
+# define CLOG2(c, p, f,a1,a2) _GRAS_LOG_PRE(_GRAS_LOGV(c),p) ,f,a1,a2 _GRAS_LOG_POST
+# define CLOG3(c, p, f,a1,a2,a3) _GRAS_LOG_PRE(_GRAS_LOGV(c),p) ,f,a1,a2,a3 _GRAS_LOG_POST
+# define CLOG4(c, p, f,a1,a2,a3,a4) _GRAS_LOG_PRE(_GRAS_LOGV(c),p) ,f,a1,a2,a3,a4 _GRAS_LOG_POST
+# define CLOG5(c, p, f,a1,a2,a3,a4,a5) _GRAS_LOG_PRE(_GRAS_LOGV(c),p) ,f,a1,a2,a3,a4,a5 _GRAS_LOG_POST
+# define CLOG6(c, p, f,a1,a2,a3,a4,a5,a6) _GRAS_LOG_PRE(_GRAS_LOGV(c),p) ,f,a1,a2,a3,a4,a5,a6 _GRAS_LOG_POST
+# define CLOG7(c, p, f,a1,a2,a3,a4,a5,a6,a7) _GRAS_LOG_PRE(_GRAS_LOGV(c),p) ,f,a1,a2,a3,a4,a5,a6,a7 _GRAS_LOG_POST
+# define CLOG8(c, p, f,a1,a2,a3,a4,a5,a6,a7,a8) _GRAS_LOG_PRE(_GRAS_LOGV(c),p) ,f,a1,a2,a3,a4,a5,a6,a7,a8 _GRAS_LOG_POST
#endif
#define CDEBUG0(c, f) CLOG0(c, gras_log_priority_debug, f)
# define LOG7(p, f,a1,a2,a3,a4,a5,a6,a7) fprintf(stderr,"%s:%d:" f "\n",__FILE__,__LINE__,a1,a2,a3,a4,a5,a6,a7)
# define LOG8(p, f,a1,a2,a3,a4,a5,a6,a7,a8) fprintf(stderr,"%s:%d:" f "\n",__FILE__,__LINE__,a1,a2,a3,a4,a5,a6,a7,a8)
#else
-# define LOG0(p, f) _GRAS_LOG_PRE((*_GRAS_LOGV(default)),p,f) _GRAS_LOG_POST
-# define LOG1(p, f,a1) _GRAS_LOG_PRE((*_GRAS_LOGV(default)),p,f) ,a1 _GRAS_LOG_POST
-# define LOG2(p, f,a1,a2) _GRAS_LOG_PRE((*_GRAS_LOGV(default)),p,f) ,a1,a2 _GRAS_LOG_POST
-# define LOG3(p, f,a1,a2,a3) _GRAS_LOG_PRE((*_GRAS_LOGV(default)),p,f) ,a1,a2,a3 _GRAS_LOG_POST
-# define LOG4(p, f,a1,a2,a3,a4) _GRAS_LOG_PRE((*_GRAS_LOGV(default)),p,f) ,a1,a2,a3,a4 _GRAS_LOG_POST
-# define LOG5(p, f,a1,a2,a3,a4,a5) _GRAS_LOG_PRE((*_GRAS_LOGV(default)),p,f) ,a1,a2,a3,a4,a5 _GRAS_LOG_POST
-# define LOG6(p, f,a1,a2,a3,a4,a5,a6) _GRAS_LOG_PRE((*_GRAS_LOGV(default)),p,f) ,a1,a2,a3,a4,a5,a6 _GRAS_LOG_POST
-# define LOG7(p, f,a1,a2,a3,a4,a5,a6,a7) _GRAS_LOG_PRE((*_GRAS_LOGV(default)),p,f) ,a1,a2,a3,a4,a5,a6,a7 _GRAS_LOG_POST
-# define LOG8(p, f,a1,a2,a3,a4,a5,a6,a7,a8) _GRAS_LOG_PRE((*_GRAS_LOGV(default)),p,f) ,a1,a2,a3,a4,a5,a6,a7,a8 _GRAS_LOG_POST
+# define LOG0(p, f) _GRAS_LOG_PRE((*_GRAS_LOGV(default)),p) ,f _GRAS_LOG_POST
+# define LOG1(p, f,a1) _GRAS_LOG_PRE((*_GRAS_LOGV(default)),p) ,f,a1 _GRAS_LOG_POST
+# define LOG2(p, f,a1,a2) _GRAS_LOG_PRE((*_GRAS_LOGV(default)),p) ,f,a1,a2 _GRAS_LOG_POST
+# define LOG3(p, f,a1,a2,a3) _GRAS_LOG_PRE((*_GRAS_LOGV(default)),p) ,f,a1,a2,a3 _GRAS_LOG_POST
+# define LOG4(p, f,a1,a2,a3,a4) _GRAS_LOG_PRE((*_GRAS_LOGV(default)),p) ,f,a1,a2,a3,a4 _GRAS_LOG_POST
+# define LOG5(p, f,a1,a2,a3,a4,a5) _GRAS_LOG_PRE((*_GRAS_LOGV(default)),p) ,f,a1,a2,a3,a4,a5 _GRAS_LOG_POST
+# define LOG6(p, f,a1,a2,a3,a4,a5,a6) _GRAS_LOG_PRE((*_GRAS_LOGV(default)),p) ,f,a1,a2,a3,a4,a5,a6 _GRAS_LOG_POST
+# define LOG7(p, f,a1,a2,a3,a4,a5,a6,a7) _GRAS_LOG_PRE((*_GRAS_LOGV(default)),p) ,f,a1,a2,a3,a4,a5,a6,a7 _GRAS_LOG_POST
+# define LOG8(p, f,a1,a2,a3,a4,a5,a6,a7,a8) _GRAS_LOG_PRE((*_GRAS_LOGV(default)),p) ,f,a1,a2,a3,a4,a5,a6,a7,a8 _GRAS_LOG_POST
#endif
/**
#define CRITICAL5(f,a1,a2,a3,a4,a5) LOG5(gras_log_priority_critical, f,a1,a2,a3,a4,a5)
#define CRITICAL6(f,a1,a2,a3,a4,a5,a6) LOG6(gras_log_priority_critical, f,a1,a2,a3,a4,a5,a6)
-#define GRAS_IN DEBUG0(">> begin of function")
-#define GRAS_OUT DEBUG0("<< end of function")
+#ifdef __GNUC__
+#define GRAS_IN LOG1(gras_log_priority_trace, ">> begin of %s", __FUNCTION__)
+#define GRAS_IN1(fmt,a) LOG2(gras_log_priority_trace, ">> begin of %s" fmt, __FUNCTION__, a)
+#define GRAS_IN2(fmt,a,b) LOG3(gras_log_priority_trace, ">> begin of %s" fmt, __FUNCTION__, a,b)
+#define GRAS_IN3(fmt,a,b,c) LOG4(gras_log_priority_trace, ">> begin of %s" fmt, __FUNCTION__, a,b,c)
+#define GRAS_IN4(fmt,a,b,c,d) LOG5(gras_log_priority_trace, ">> begin of %s" fmt, __FUNCTION__, a,b,c,d)
+#define GRAS_OUT LOG1(gras_log_priority_trace, "<< end of %s", __FUNCTION__)
+#else /* if fool enough to compile without gcc */
+#define GRAS_IN LOG0(gras_log_priority_trace, ">> begin of function")
+#define GRAS_IN1(fmt,a) LOG2(gras_log_priority_trace, ">> begin of function " fmt, a)
+#define GRAS_IN2(fmt,a,b) LOG3(gras_log_priority_trace, ">> begin of function " fmt, a,b)
+#define GRAS_IN3(fmt,a,b,c) LOG4(gras_log_priority_trace, ">> begin of function " fmt, a,b,c)
+#define GRAS_IN4(fmt,a,b,c,d) LOG5(gras_log_priority_trace, ">> begin of function " fmt, a,b,c,d)
+
+#define GRAS_OUT(fmt,a) LOG0(gras_log_priority_trace, "<< end of function")
+#endif /* end of foolness for non-gcc */
#endif /* ! _GRAS_LOG_H_ */