appender.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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 <stdio.h>
  21. #include "log4c/defs.h"
  22. #include "log4c/layout.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 TCHAR* 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 TCHAR* 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(const log4c_appender_type_t* a_type);
  76. /**
  77. * Get a pointer to an existing appender.
  78. *
  79. * @param a_name the name of the appender to return.
  80. * @returns a pointer to an existing appender, or NULL if no appender
  81. * with the specfied name exists.
  82. **/
  83. LOG4C_API log4c_appender_t* log4c_appender_get(const TCHAR* a_name);
  84. /**
  85. * Constructor for log4c_appender_t.
  86. **/
  87. LOG4C_API log4c_appender_t* log4c_appender_new(const TCHAR* a_name);
  88. /**
  89. * Destructor for log4c_appender_t.
  90. **/
  91. LOG4C_API void log4c_appender_delete(log4c_appender_t* a_appender);
  92. /**
  93. * @param a_appender the log4c_appender_t object
  94. * @return the appender name
  95. **/
  96. LOG4C_API const TCHAR* log4c_appender_get_name(const log4c_appender_t* a_appender);
  97. /**
  98. * @param a_appender the log4c_appender_t object
  99. * @return the appender operations
  100. **/
  101. LOG4C_API const log4c_appender_type_t* log4c_appender_get_type(const log4c_appender_t* a_appender);
  102. /**
  103. * @param a_appender the log4c_appender_t object
  104. * @return the appender layout
  105. **/
  106. LOG4C_API const log4c_layout_t* log4c_appender_get_layout(const log4c_appender_t* a_appender);
  107. /**
  108. * @param a_appender the log4c_appender_t object
  109. * @return the appender user data
  110. **/
  111. LOG4C_API void* log4c_appender_get_udata(const log4c_appender_t* a_appender);
  112. /**
  113. * sets the appender type
  114. *
  115. * @param a_appender the log4c_appender_t object
  116. * @param a_type the new appender type
  117. * @return the previous appender type
  118. **/
  119. LOG4C_API const log4c_appender_type_t* log4c_appender_set_type(log4c_appender_t* a_appender,const log4c_appender_type_t* a_type);
  120. /**
  121. * sets the appender user data
  122. *
  123. * @param a_appender the log4c_appender_t object
  124. * @param a_udata the new appender user data
  125. * @return the previous appender user data
  126. **/
  127. LOG4C_API void* log4c_appender_set_udata(log4c_appender_t* a_appender, void* a_udata);
  128. /**
  129. * sets the appender layout
  130. *
  131. * @param a_appender the log4c_appender_t object
  132. * @param a_layout the new appender layout
  133. * @return the previous appender layout
  134. **/
  135. LOG4C_API const log4c_layout_t* log4c_appender_set_layout(log4c_appender_t* a_appender,const log4c_layout_t* a_layout);
  136. /**
  137. * opens the appender.
  138. *
  139. * @param a_appender the log4c_appender_t object
  140. **/
  141. LOG4C_API int log4c_appender_open(log4c_appender_t* a_appender);
  142. /**
  143. * log in appender specific way.
  144. *
  145. * @param a_appender the log4c_appender object
  146. * @param a_event the log4c_logging_event_t object to log.
  147. **/
  148. LOG4C_API int log4c_appender_append(log4c_appender_t* a_appender,log4c_logging_event_t* a_event);
  149. /**
  150. * log in appender specific way.
  151. *
  152. * @param a_appender the log4c_appender object
  153. * @param a_event the log4c_logging_event_t object to log.
  154. **/
  155. LOG4C_API int log4c_appender_append_no_file_num_no_layout(log4c_appender_t* a_appender,log4c_logging_event_t* a_event);
  156. /**
  157. * closes the appender
  158. *
  159. * @param a_appender the log4c_appender_t object
  160. * @return zero if successful, -1 otherwise
  161. **/
  162. LOG4C_API int log4c_appender_close(log4c_appender_t* a_appender);
  163. /**
  164. * prints the appender on a stream
  165. *
  166. * @param a_appender the log4c_appender_t object
  167. * @param a_stream the stream
  168. **/
  169. LOG4C_API void log4c_appender_print(const log4c_appender_t* a_appender, FILE* a_stream);
  170. /**
  171. * prints all the current registered appender types on a stream
  172. *
  173. * @param fp the stream
  174. **/
  175. LOG4C_API void log4c_appender_types_print(FILE *fp);
  176. /** 删除本appender.c文件中定义的全局和静态的指针指向的内存,防止内存泄漏
  177. 如:
  178. 1.gs_types.
  179. 2.
  180. @return void.
  181. 作者:jesse 日期:2008.09.08
  182. */
  183. LOG4C_API void log4c_appender_delete_global();
  184. /**
  185. * Helper macro to define static appender types.
  186. *
  187. * @param a_type the log4c_appender_type_t object to define
  188. * @warning needs GCC support: otherwise this macro does nothing
  189. * @deprecated This macro, and the static initialialization
  190. * of appenders in general, is deprecated. Use rather
  191. * the log4c_appender_type_set() function to initialize your appenders
  192. * before calling log4c_init()
  193. *
  194. **/
  195. #ifdef __GNUC__
  196. # define log4c_appender_type_define(a_type) \
  197. typedef int log4c_appender_type_define_##a_type __attribute__((deprecated)); \
  198. static log4c_appender_type_define_##a_type __unsused_var __attribute__ ((unused));
  199. #else
  200. # define log4c_appender_type_define(a_type)
  201. #endif
  202. /**
  203. * @internal
  204. **/
  205. struct __sd_factory;
  206. LOG4C_API struct __sd_factory* log4c_appender_factory;
  207. __LOG4C_END_DECLS
  208. #endif