summaryrefslogtreecommitdiff
path: root/include/nslog
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2017-06-10 20:48:38 +0100
committerDaniel Silverstone <dsilvers@digital-scurf.org>2017-06-10 20:48:38 +0100
commit8052642eadfb95b244f978b10889dff51f9133f5 (patch)
treec8287316266cf98b5886cbef2fa5a44551d40982 /include/nslog
parent551cf378a93588d42732983ec30716e14afef945 (diff)
downloadlibnslog-8052642eadfb95b244f978b10889dff51f9133f5.tar.gz
libnslog-8052642eadfb95b244f978b10889dff51f9133f5.tar.bz2
Rework to only allocate one thing in the corked state and nothing in the uncorked state
Diffstat (limited to 'include/nslog')
-rw-r--r--include/nslog/nslog.h45
1 files changed, 23 insertions, 22 deletions
diff --git a/include/nslog/nslog.h b/include/nslog/nslog.h
index fff31a7..ffa87bd 100644
--- a/include/nslog/nslog.h
+++ b/include/nslog/nslog.h
@@ -15,6 +15,8 @@
#ifndef NSLOG_NSLOG_H_
#define NSLOG_NSLOG_H_
+#include <stdarg.h>
+
typedef enum {
NSLOG_LEVEL_DEEPDEBUG = 0,
NSLOG_LEVEL_DEBUG = 1,
@@ -45,16 +47,15 @@ typedef struct nslog_category_s {
struct nslog_category_s *next;
} nslog_category_t;
-typedef struct nslog_entry_s {
+typedef struct nslog_entry_context_s {
nslog_category_t *category;
nslog_level level;
const char *filename;
const char *funcname;
int lineno;
- char message[0]; /* NUL terminated */
-} nslog_entry_t;
+} nslog_entry_context_t;
-#define NSLOG_DECLARE_CATEGORY(catname) \
+#define NSLOG_DECLARE_CATEGORY(catname) \
extern nslog_category_t __nslog_category_##catname
#define NSLOG_DEFINE_CATEGORY(catname, description) \
@@ -75,31 +76,31 @@ typedef struct nslog_entry_s {
NULL, \
}
-#define NSLOG(catname, level, logmsg, args...) \
- if (NSLOG_LEVEL_##level >= NSLOG_COMPILED_MIN_LEVEL) { \
- nslog__log(&__nslog_category_##catname, \
- NSLOG_LEVEL_##level, \
- __FILE__, \
- __LINE__, \
- __PRETTY_FUNCTION__, \
- logmsg, \
- ##args); \
- }
-
-void nslog__log(nslog_category_t *category,
- nslog_level level,
- const char *filename,
- int lineno,
- const char *funcname,
+#define NSLOG(catname, level, logmsg, args...) \
+ do { \
+ if (NSLOG_LEVEL_##level >= NSLOG_COMPILED_MIN_LEVEL) { \
+ nslog_entry_context_t ctx = { \
+ &__nslog_category_##catname, \
+ NSLOG_LEVEL_##level, \
+ __FILE__, \
+ __PRETTY_FUNCTION__, \
+ __LINE__, \
+ }; \
+ nslog__log(&ctx, logmsg, ##args); \
+ } \
+ } while(0)
+
+void nslog__log(nslog_entry_context_t *ctx,
const char *pattern,
- ...) __attribute__ ((format (printf, 6, 7)));
+ ...) __attribute__ ((format (printf, 2, 3)));
typedef enum {
NSLOG_NO_ERROR = 0,
NSLOG_NO_MEMORY = 1,
} nslog_error;
-typedef void (*nslog_callback)(void *context, nslog_entry_t *msg);
+typedef void (*nslog_callback)(void *context, nslog_entry_context_t *ctx,
+ const char *fmt, va_list args);
nslog_error nslog_set_render_callback(nslog_callback cb, void *context);