diff options
Diffstat (limited to 'lib/log.h')
-rw-r--r-- | lib/log.h | 107 |
1 files changed, 88 insertions, 19 deletions
@@ -19,13 +19,14 @@ * You should have received a copy of the GNU General Public License * along with GNU Zebra; see the file COPYING. If not, write to the Free * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. + * 02111-1307, USA. */ #ifndef _ZEBRA_LOG_H #define _ZEBRA_LOG_H #include <syslog.h> +#include "pthread_safe.h" /* Here is some guidance on logging levels to use: * @@ -43,7 +44,7 @@ * please use LOG_ERR instead. */ -typedef enum +typedef enum { ZLOG_NONE, ZLOG_DEFAULT, @@ -51,7 +52,7 @@ typedef enum ZLOG_RIP, ZLOG_BGP, ZLOG_OSPF, - ZLOG_RIPNG, + ZLOG_RIPNG, ZLOG_OSPF6, ZLOG_ISIS, ZLOG_MASC @@ -70,7 +71,7 @@ typedef enum } zlog_dest_t; #define ZLOG_NUM_DESTS (ZLOG_DEST_FILE+1) -struct zlog +struct zlog { const char *ident; /* daemon name (first arg to openlog) */ zlog_proto_t protocol; @@ -93,7 +94,11 @@ struct message const char *str; }; -/* Default logging strucutre. */ +/* module initialization */ +extern void zlog_init_r(void); +extern void zlog_destroy_r(void); + +/* Default logging structure. */ extern struct zlog *zlog_default; /* Open zlog function */ @@ -113,6 +118,9 @@ extern void closezlog (struct zlog *zl); /* Generic function for zlog. */ extern void zlog (struct zlog *zl, int priority, const char *format, ...) PRINTF_ATTRIBUTE(3, 4); +/* assumed locked version for close friends */ +extern void uzlog (struct zlog *zl, int priority, const char *format, ...) + PRINTF_ATTRIBUTE(3, 4); /* Handy zlog functions. */ extern void zlog_err (const char *format, ...) PRINTF_ATTRIBUTE(1, 2); @@ -147,11 +155,28 @@ extern int zlog_reset_file (struct zlog *zl); /* Rotate log. */ extern int zlog_rotate (struct zlog *); +/* getters & setters */ +extern int zlog_get_default_lvl (struct zlog *zl); +extern void zlog_set_default_lvl (struct zlog *zl, int level); +extern void zlog_set_default_lvl_dest (struct zlog *zl, int level); +extern int zlog_get_maxlvl (struct zlog *zl, zlog_dest_t dest); +extern int zlog_get_facility (struct zlog *zl); +extern void zlog_set_facility (struct zlog *zl, int facility); +extern int zlog_get_record_priority (struct zlog *zl); +extern void zlog_set_record_priority (struct zlog *zl, int record_priority); +extern int zlog_get_timestamp_precision (struct zlog *zl); +extern void zlog_set_timestamp_precision (struct zlog *zl, int timestamp_precision); +extern const char * zlog_get_ident (struct zlog *zl); +extern char * zlog_get_filename (struct zlog *zl); +extern int zlog_is_file (struct zlog *zl); +extern const char * zlog_get_proto_name (struct zlog *zl); +extern const char * uzlog_get_proto_name (struct zlog *zl); + /* For hackey massage lookup and check */ #define LOOKUP(x, y) mes_lookup(x, x ## _max, y, "(no item found)") extern const char *lookup (const struct message *, int); -extern const char *mes_lookup (const struct message *meslist, +extern const char *mes_lookup (const struct message *meslist, int max, int index, const char *no_item); @@ -168,6 +193,9 @@ extern void zlog_signal(int signo, const char *action #endif ); +/* Ring down the curtain -- turn of SIGABRT handler and abort() */ +extern void zabort_abort(void) __attribute__ ((noreturn)) ; + /* Log a backtrace. */ extern void zlog_backtrace(int priority); @@ -178,25 +206,66 @@ extern void zlog_backtrace(int priority); extern void zlog_backtrace_sigsafe(int priority, void *program_counter); /* Puts a current timestamp in buf and returns the number of characters - written (not including the terminating NUL). The purpose of - this function is to avoid calls to localtime appearing all over the code. - It caches the most recent localtime result and can therefore - avoid multiple calls within the same second. If buflen is too small, - *buf will be set to '\0', and 0 will be returned. */ + * written (not including the terminating NUL). The purpose of + * this function is to avoid calls to localtime appearing all over the code. + * It caches the most recent localtime result and can therefore + * avoid multiple calls within the same second. + * + * The buflen MUST be > 1 and the buffer address MUST NOT be NULL. + * + * If buflen is too small, writes buflen-1 characters followed by '\0'. + * + * Time stamp is rendered in the form: %Y/%m/%d %H:%M:%S + * + * This has a fixed length (leading zeros are included) of 19 characters + * (unless this code is still in use beyond the year 9999 !) + * + * Which may be followed by "." and a number of decimal digits, usually 1..6. + * + * So the maximum time stamp is 19 + 1 + 6 = 26. Adding the trailing '\n', and + * rounding up for good measure -- buffer size = 32. + */ +#define TIMESTAMP_FORM "%Y/%m/%d %H:%M:%S" + +enum { timestamp_buffer_len = 32 } ; + extern size_t quagga_timestamp(int timestamp_precision /* # subsecond digits */, char *buf, size_t buflen); -/* structure useful for avoiding repeated rendering of the same timestamp */ -struct timestamp_control { - size_t len; /* length of rendered timestamp */ - int precision; /* configuration parameter */ - int already_rendered; /* should be initialized to 0 */ - char buf[40]; /* will contain the rendered timestamp */ -}; +/* Generate line to be logged + * + * Structure used to hold line for log output -- so that need be generated + * just once even if output to multiple destinations. + * + * Note that the buffer length is a hard limit (including terminating '\n''\0' + * or '\r''\n''\0'). Do not wish to malloc any larger buffer while logging. + */ +enum { logline_buffer_len = 1008 } ; +enum ll_term +{ + llt_nul = 0, /* NB: also length of the terminator */ + llt_lf = 1, + llt_crlf = 2, +} ; + +struct logline { + char* p_nl ; /* address of the terminator */ + + enum ll_term term ; /* how line is terminated */ + + size_t len ; /* length including either '\r''\n' or '\n' */ + + char line[logline_buffer_len]; /* buffer */ +} ; + +extern void +uvzlog_line(struct logline* ll, struct zlog *zl, int priority, + const char *format, va_list va, enum ll_term term) ; /* Defines for use in command construction: */ -#define LOG_LEVELS "(emergencies|alerts|critical|errors|warnings|notifications|informational|debugging)" +#define LOG_LEVELS "(emergencies|alerts|critical|errors|" \ + "warnings|notifications|informational|debugging)" #define LOG_LEVEL_DESC \ "System is unusable\n" \ |