appender.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. /* $Id$
  2. *
  3. * appender.h
  4. *
  5. * Copyright 2001-2003, Meiosys (www.meiosys.com). All rights reserved.
  6. *
  7. * See the COPYING file for the terms of usage and distribution.
  8. */
  9. #ifndef log4c_appender_h
  10. #define log4c_appender_h
  11. /**
  12. * @file appender.h
  13. *
  14. * @brief Implement this interface for your own strategies for printing log
  15. * statements.
  16. *
  17. * @todo the appender interface needs a better configuration system
  18. * depending on the layout type. The udata field is a just a trick.
  19. **/
  20. #include <log4c/defs.h>
  21. #include <log4c/layout.h>
  22. #include <stdio.h>
  23. __LOG4C_BEGIN_DECLS
  24. struct __log4c_appender;
  25. /**
  26. * log4c appender class
  27. **/
  28. typedef struct __log4c_appender log4c_appender_t;
  29. /**
  30. * @brief log4c appender type class
  31. *
  32. * Attributes description:
  33. *
  34. * @li @c name appender type name
  35. * @li @c open
  36. * @li @c append
  37. * @li @c close
  38. **/
  39. typedef struct log4c_appender_type {
  40. const char* name;
  41. int (*open) (log4c_appender_t*);
  42. int (*append) (log4c_appender_t*, const log4c_logging_event_t*);
  43. int (*close) (log4c_appender_t*);
  44. } log4c_appender_type_t;
  45. /**
  46. * Get a pointer to an existing appender type.
  47. *
  48. * @param a_name the name of the appender type to return.
  49. * @returns a pointer to an existing appender type, or NULL if no appender
  50. * type with the specified name exists.
  51. **/
  52. LOG4C_API const log4c_appender_type_t* log4c_appender_type_get(const char* a_name);
  53. /**
  54. * Use this function to register an appender type with log4c.
  55. * Once this is done you may refer to this type by name both
  56. * programmatically and in the log4c
  57. * configuration file.
  58. *
  59. * @param a_type a pointer to the new appender type to set.
  60. * @returns a pointer to the previous appender type of same name.
  61. *
  62. * Example code fragment:
  63. * @code
  64. *
  65. * const log4c_appender_type_t log4c_appender_type_s13_file = {
  66. * "s13_file",
  67. * s13_file_open,
  68. * s13_file_append,
  69. * s13_file_close,
  70. * };
  71. *
  72. * log4c_appender_type_set(&log4c_appender_type_s13_file);
  73. * @endcode
  74. **/
  75. LOG4C_API const log4c_appender_type_t* log4c_appender_type_set(
  76. const log4c_appender_type_t* a_type);
  77. /**
  78. * Get a pointer to an existing appender.
  79. *
  80. * @param a_name the name of the appender to return.
  81. * @returns a pointer to an existing appender, or NULL if no appender
  82. * with the specfied name exists.
  83. **/
  84. LOG4C_API log4c_appender_t* log4c_appender_get(const char* a_name);
  85. /**
  86. * Constructor for log4c_appender_t.
  87. **/
  88. LOG4C_API log4c_appender_t* log4c_appender_new(const char* a_name);
  89. /**
  90. * Destructor for log4c_appender_t.
  91. **/
  92. LOG4C_API void log4c_appender_delete(log4c_appender_t* a_appender);
  93. /**
  94. * @param a_appender the log4c_appender_t object
  95. * @return the appender name
  96. **/
  97. LOG4C_API const char* log4c_appender_get_name(const log4c_appender_t* a_appender);
  98. /**
  99. * @param a_appender the log4c_appender_t object
  100. * @return the appender operations
  101. **/
  102. LOG4C_API const log4c_appender_type_t* log4c_appender_get_type(
  103. const log4c_appender_t* a_appender);
  104. /**
  105. * @param a_appender the log4c_appender_t object
  106. * @return the appender layout
  107. **/
  108. LOG4C_API const log4c_layout_t* log4c_appender_get_layout(
  109. const log4c_appender_t* a_appender);
  110. /**
  111. * @param a_appender the log4c_appender_t object
  112. * @return the appender user data
  113. **/
  114. LOG4C_API void* log4c_appender_get_udata(const log4c_appender_t* a_appender);
  115. /**
  116. * sets the appender type
  117. *
  118. * @param a_appender the log4c_appender_t object
  119. * @param a_type the new appender type
  120. * @return the previous appender type
  121. **/
  122. LOG4C_API const log4c_appender_type_t* log4c_appender_set_type(
  123. log4c_appender_t* a_appender,
  124. const log4c_appender_type_t* a_type);
  125. /**
  126. * sets the appender user data
  127. *
  128. * @param a_appender the log4c_appender_t object
  129. * @param a_udata the new appender user data
  130. * @return the previous appender user data
  131. **/
  132. LOG4C_API void* log4c_appender_set_udata(log4c_appender_t* a_appender,
  133. void* a_udata);
  134. /**
  135. * sets the appender layout
  136. *
  137. * @param a_appender the log4c_appender_t object
  138. * @param a_layout the new appender layout
  139. * @return the previous appender layout
  140. **/
  141. LOG4C_API const log4c_layout_t* log4c_appender_set_layout(
  142. log4c_appender_t* a_appender,
  143. const log4c_layout_t* a_layout);
  144. /**
  145. * opens the appender.
  146. *
  147. * @param a_appender the log4c_appender_t object
  148. **/
  149. LOG4C_API int log4c_appender_open(log4c_appender_t* a_appender);
  150. /**
  151. * log in appender specific way.
  152. *
  153. * @param a_appender the log4c_appender object
  154. * @param a_event the log4c_logging_event_t object to log.
  155. **/
  156. LOG4C_API int log4c_appender_append(
  157. log4c_appender_t* a_appender,
  158. log4c_logging_event_t* a_event);
  159. /**
  160. * log in appender specific way.
  161. *
  162. * @param a_appender the log4c_appender object
  163. * @param a_event the log4c_logging_event_t object to log.
  164. **/
  165. LOG4C_API int log4c_appender_append_no_file_num_no_layout(
  166. log4c_appender_t* a_appender,
  167. log4c_logging_event_t* a_event);
  168. /**
  169. * closes the appender
  170. *
  171. * @param a_appender the log4c_appender_t object
  172. * @return zero if successful, -1 otherwise
  173. **/
  174. LOG4C_API int log4c_appender_close(log4c_appender_t* a_appender);
  175. /**
  176. * prints the appender on a stream
  177. *
  178. * @param a_appender the log4c_appender_t object
  179. * @param a_stream the stream
  180. **/
  181. LOG4C_API void log4c_appender_print(const log4c_appender_t* a_appender,
  182. FILE* a_stream);
  183. /**
  184. * prints all the current registered appender types on a stream
  185. *
  186. * @param fp the stream
  187. **/
  188. LOG4C_API void log4c_appender_types_print(FILE *fp);
  189. /** 删除本appender.c文件中定义的全局和静态的指针指向的内存,防止内存泄漏
  190. 如:
  191. 1.gs_types.
  192. 2.
  193. @return void.
  194. 作者:jesse 日期:2008.09.08
  195. */
  196. LOG4C_API void log4c_appender_delete_global();
  197. /**
  198. * Helper macro to define static appender types.
  199. *
  200. * @param a_type the log4c_appender_type_t object to define
  201. * @warning needs GCC support: otherwise this macro does nothing
  202. * @deprecated This macro, and the static initialialization
  203. * of appenders in general, is deprecated. Use rather
  204. * the log4c_appender_type_set() function to initialize your appenders
  205. * before calling log4c_init()
  206. *
  207. **/
  208. #ifdef __GNUC__
  209. # define log4c_appender_type_define(a_type) \
  210. typedef int log4c_appender_type_define_##a_type __attribute__((deprecated)); \
  211. static log4c_appender_type_define_##a_type __unsused_var __attribute__ ((unused));
  212. #else
  213. # define log4c_appender_type_define(a_type)
  214. #endif
  215. /**
  216. * @internal
  217. **/
  218. struct __sd_factory;
  219. LOG4C_API struct __sd_factory* log4c_appender_factory;
  220. __LOG4C_END_DECLS
  221. #endif