Main Page | Modules | Data Structures | File List | Data Fields

log.h

00001 /* 
00002  * Copyright (c) 2005, 2006 by KoanLogic s.r.l. - All rights reserved.  
00003  */
00004 
00005 #ifndef _U_LOG_H_
00006 #define _U_LOG_H_
00007 #include "libu_conf.h"
00008 
00009 #include <stdlib.h>
00010 #include <stdarg.h>
00011 #include <stdio.h>
00012 
00013 #include <u/os.h>
00014 #include <u/logprv.h>
00015 
00016 #ifdef __cplusplus
00017 extern "C" {
00018 #endif
00019 
00054 /* messages longer then U_MAX_LOG_LENGTH will be silently discarded */
00055 enum { U_MAX_LOG_LENGTH  = 1024 };
00056 
00065 extern int facility;
00066 
00068 typedef int (*u_log_hook_t)(void *arg, int level, const char *str); 
00069 
00087 int u_log_set_hook(u_log_hook_t hook, void *arg, u_log_hook_t *old, void**parg);
00088 
00098 #define u_log_err(ecode, facility, ctx, ...) \
00099     do {                                                    \
00100         u_log_write(facility, LOG_ERR, ctx, __VA_ARGS__);   \
00101         exit(ecode);                                        \
00102     } while(0)
00103 
00112 #define u_log_warning(facility, ctx, ...) \
00113     u_log_write(facility, LOG_WARNING, ctx, __VA_ARGS__)
00114 
00123 #define u_log_info(facility, ctx, ...) \
00124     u_log_write(facility, LOG_INFO, ctx, __VA_ARGS__)
00125 
00134 #define u_log_debug(facility, ctx, ...) \
00135     u_log_write(facility, LOG_DEBUG, ctx, __VA_ARGS__)
00136 
00138 #define die(ecode, ...) u_log_err(ecode, facility, 1, __VA_ARGS__)
00139 
00141 #define die_if(expr) if(expr) die(EXIT_FAILURE, #expr)
00142 
00144 #define warning(...) u_log_warning(facility, 1, __VA_ARGS__)
00145 
00147 #define info(...) u_log_info(facility, 0, __VA_ARGS__)
00148 
00150 #define debug(...) u_log_debug(facility, 1, __VA_ARGS__)
00151 
00153 #define console(...) \
00154     (fprintf(stderr, __VA_ARGS__) && fprintf(stderr, "\n"))
00155 
00160 #ifdef __cplusplus
00161 }
00162 #endif
00163 
00164 #endif /* !_U_LOG_H_ */

←Products
© 2005-2006 - KoanLogic S.r.l. - All rights reserved