layout.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /* $Id$
  2. *
  3. * layout.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_layout_h
  10. #define log4c_layout_h
  11. /**
  12. * @file layout.h
  13. *
  14. * @brief Interface for user specific layout format of log4c_logging_event
  15. * events.
  16. *
  17. * @todo the layout interface needs a better configuration system
  18. * depending on the layout type. The udata field is a just a trick.
  19. *
  20. * @todo a pattern layout would be welcomed !!
  21. **/
  22. #include <log4c/defs.h>
  23. #include <log4c/logging_event.h>
  24. #include <stdio.h>
  25. __LOG4C_BEGIN_DECLS
  26. struct __log4c_layout;
  27. /**
  28. * log4c layout class
  29. **/
  30. typedef struct __log4c_layout log4c_layout_t;
  31. /**
  32. * @brief log4c layout type class
  33. *
  34. * Attributes description:
  35. *
  36. * @li @c name layout type name
  37. * @li @c format
  38. **/
  39. typedef struct log4c_layout_type {
  40. const char* name;
  41. const char* (*format) (const log4c_layout_t*, const log4c_logging_event_t*);
  42. } log4c_layout_type_t;
  43. /**
  44. * Get a pointer to an existing layout type.
  45. *
  46. * @param a_name the name of the layout type to return.
  47. * @returns a pointer to an existing layout type, or NULL if no layout
  48. * type with the specified name exists.
  49. **/
  50. LOG4C_API const log4c_layout_type_t* log4c_layout_type_get(const char* a_name);
  51. /**
  52. * Use this function to register a layout type with log4c.
  53. * Once this is done you may refer to this type by name both
  54. * programatically and in the log4c configuration file.
  55. *
  56. * @param a_type a pointer to the new layout type to set.
  57. * @returns a pointer to the previous layout type of same name.
  58. *
  59. * Example code fragment:
  60. * @code
  61. *
  62. * const log4c_layout_type_t log4c_layout_type_xml = {
  63. * "s13_xml",
  64. * xml_format,
  65. * };
  66. *
  67. * log4c_layout_type_set(&log4c_layout_type_xml);
  68. *
  69. * @endcode
  70. **/
  71. LOG4C_API const log4c_layout_type_t* log4c_layout_type_set(
  72. const log4c_layout_type_t* a_type);
  73. /**
  74. * Get a pointer to an existing layout.
  75. *
  76. * @param a_name the name of the layout to return.
  77. * @returns a pointer to an existing layout, or NULL if no layout
  78. * with the specfied name exists.
  79. **/
  80. LOG4C_API log4c_layout_t* log4c_layout_get(const char* a_name);
  81. /**
  82. * Constructor for layout.
  83. **/
  84. LOG4C_API log4c_layout_t* log4c_layout_new(const char* a_name);
  85. /**
  86. * Destructor for layout.
  87. **/
  88. LOG4C_API void log4c_layout_delete(log4c_layout_t* a_layout);
  89. /**
  90. * @param a_layout the log4c_layout_t object
  91. * @return the layout name
  92. **/
  93. LOG4C_API const char* log4c_layout_get_name(const log4c_layout_t* a_layout);
  94. /**
  95. * @param a_layout the log4c_layout_t object
  96. * @return a log4c_layout_type_t object
  97. **/
  98. LOG4C_API const log4c_layout_type_t* log4c_layout_get_type(
  99. const log4c_layout_t* a_layout);
  100. /**
  101. * sets the layout type
  102. *
  103. * @param a_layout the log4c_layout_t object
  104. * @param a_type the new layout type
  105. * @return the previous layout type
  106. *
  107. **/
  108. LOG4C_API const log4c_layout_type_t* log4c_layout_set_type(
  109. log4c_layout_t* a_layout,
  110. const log4c_layout_type_t* a_type);
  111. /**
  112. * @param a_layout the log4c_layout_t object
  113. * @return the layout user data
  114. **/
  115. LOG4C_API void* log4c_layout_get_udata(const log4c_layout_t* a_layout);
  116. /**
  117. * sets the layout user data
  118. *
  119. * @param a_layout the log4c_layout_t object
  120. * @param a_udata the new layout user data
  121. * @return the previous layout user data
  122. **/
  123. LOG4C_API void* log4c_layout_set_udata(log4c_layout_t* a_layout,
  124. void* a_udata);
  125. /**
  126. * format a log4c_logging_event events to a string.
  127. *
  128. * @param a_layout the log4c_layout_t object
  129. * @param a_event a logging_event_t object
  130. * @returns an appendable string.
  131. **/
  132. LOG4C_API const char* log4c_layout_format(
  133. const log4c_layout_t* a_layout,
  134. const log4c_logging_event_t* a_event);
  135. /**
  136. * prints the layout on a stream
  137. * @param a_layout the log4c_layout_t object
  138. * @param a_stream the stream
  139. **/
  140. LOG4C_API void log4c_layout_print(
  141. const log4c_layout_t* a_layout, FILE* a_stream);
  142. /**
  143. * prints all the current registered layout types on a stream
  144. *
  145. * @param fp the stream
  146. **/
  147. LOG4C_API void log4c_layout_types_print(FILE *fp);
  148. /** 删除本layout.c文件中定义的全局和静态的指针指向的内存,防止内存泄漏
  149. 如:
  150. 1.gs_types.
  151. 2.
  152. @return void.
  153. 作者:jesse 日期:2008.09.08
  154. */
  155. LOG4C_API void log4c_layout_delete_global();
  156. /**
  157. * Helper macro to define static layout types.
  158. *
  159. * @param a_type the log4c_layout_type_t object to define
  160. * @warning needs GCC support: otherwise this macro does nothing
  161. * @deprecated This macro, and the static initialialization
  162. * of layouts in general, is deprecated. Use rather
  163. * the log4c_layout_type_set() function to initialize your appenders
  164. * before calling log4c_init()
  165. **/
  166. #ifdef __GNUC__
  167. # define log4c_layout_type_define(a_type) \
  168. typedef int log4c_layout_type_define_##a_type __attribute__((deprecated)); \
  169. static log4c_layout_type_define_##a_type __unsused_var __attribute__((unused));
  170. #else
  171. # define log4c_layout_type_define(a_type)
  172. #endif
  173. /**
  174. * @internal
  175. **/
  176. struct __sd_factory;
  177. LOG4C_API struct __sd_factory* log4c_layout_factory;
  178. __LOG4C_END_DECLS
  179. #endif