log.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /* Zebra logging funcions.
  2. * Copyright (C) 1997, 1998, 1999 Kunihiro Ishiguro
  3. *
  4. * This file is part of GNU Zebra.
  5. *
  6. * GNU Zebra is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the
  8. * Free Software Foundation; either version 2, or (at your option) any
  9. * later version.
  10. *
  11. * GNU Zebra is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with GNU Zebra; see the file COPYING. If not, write to the Free
  18. * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  19. * 02111-1307, USA.
  20. */
  21. #ifndef _ZEBRA_LOG_H
  22. #define _ZEBRA_LOG_H
  23. #include <syslog.h>
  24. #define ZLOG_NOLOG 0x00
  25. #define ZLOG_FILE 0x01
  26. #define ZLOG_SYSLOG 0x02
  27. #define ZLOG_STDOUT 0x04
  28. #define ZLOG_STDERR 0x08
  29. #define ZLOG_NOLOG_INDEX 0
  30. #define ZLOG_FILE_INDEX 1
  31. #define ZLOG_SYSLOG_INDEX 2
  32. #define ZLOG_STDOUT_INDEX 3
  33. #define ZLOG_STDERR_INDEX 4
  34. #define ZLOG_MAX_INDEX 5
  35. typedef enum
  36. {
  37. ZLOG_NONE,
  38. ZLOG_DEFAULT,
  39. ZLOG_ZEBRA,
  40. ZLOG_RIP,
  41. ZLOG_BGP,
  42. ZLOG_OSPF,
  43. ZLOG_RIPNG,
  44. ZLOG_OSPF6,
  45. ZLOG_ISIS,
  46. ZLOG_MASC
  47. } zlog_proto_t;
  48. struct zlog
  49. {
  50. const char *ident;
  51. zlog_proto_t protocol;
  52. int flags;
  53. FILE *fp;
  54. char *filename;
  55. int syslog;
  56. int stat;
  57. int connected;
  58. int maskpri; /* as per syslog setlogmask */
  59. int priority; /* as per syslog priority */
  60. int facility; /* as per syslog facility */
  61. int record_priority;
  62. };
  63. /* Message structure. */
  64. struct message
  65. {
  66. int key;
  67. char *str;
  68. };
  69. /* Default logging strucutre. */
  70. extern struct zlog *zlog_default;
  71. /* Open zlog function */
  72. struct zlog *openzlog (const char *, int, zlog_proto_t, int, int);
  73. /* Close zlog function. */
  74. void closezlog (struct zlog *zl);
  75. /* GCC have printf type attribute check. */
  76. #ifdef __GNUC__
  77. #define PRINTF_ATTRIBUTE(a,b) __attribute__ ((__format__ (__printf__, a, b)))
  78. #else
  79. #define PRINTF_ATTRIBUTE(a,b)
  80. #endif /* __GNUC__ */
  81. /* Generic function for zlog. */
  82. void zlog (struct zlog *zl, int priority, const char *format, ...) PRINTF_ATTRIBUTE(3, 4);
  83. /* Handy zlog functions. */
  84. void zlog_err (const char *format, ...) PRINTF_ATTRIBUTE(1, 2);
  85. void zlog_warn (const char *format, ...) PRINTF_ATTRIBUTE(1, 2);
  86. void zlog_info (const char *format, ...) PRINTF_ATTRIBUTE(1, 2);
  87. void zlog_notice (const char *format, ...) PRINTF_ATTRIBUTE(1, 2);
  88. void zlog_debug (const char *format, ...) PRINTF_ATTRIBUTE(1, 2);
  89. /* For bgpd's peer oriented log. */
  90. void plog_err (struct zlog *, const char *format, ...);
  91. void plog_warn (struct zlog *, const char *format, ...);
  92. void plog_info (struct zlog *, const char *format, ...);
  93. void plog_notice (struct zlog *, const char *format, ...);
  94. void plog_debug (struct zlog *, const char *format, ...);
  95. /* Set zlog flags. */
  96. void zlog_set_flag (struct zlog *zl, int flags);
  97. void zlog_reset_flag (struct zlog *zl, int flags);
  98. /* Set zlog filename. */
  99. int zlog_set_file (struct zlog *zl, int flags, char *filename);
  100. int zlog_reset_file (struct zlog *zl);
  101. /* Rotate log. */
  102. int zlog_rotate ();
  103. /* For hackey massage lookup and check */
  104. #define LOOKUP(x, y) mes_lookup(x, x ## _max, y)
  105. char *lookup (struct message *, int);
  106. char *mes_lookup (struct message *meslist, int max, int index);
  107. extern const char *zlog_priority[];
  108. #endif /* _ZEBRA_LOG_H */