layout.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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 TCHAR* name;
  41. const TCHAR* (*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 TCHAR* 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(const log4c_layout_type_t* a_type);
  72. /**
  73. * Get a pointer to an existing layout.
  74. *
  75. * @param a_name the name of the layout to return.
  76. * @returns a pointer to an existing layout, or NULL if no layout
  77. * with the specfied name exists.
  78. **/
  79. LOG4C_API log4c_layout_t* log4c_layout_get(const TCHAR* a_name);
  80. /**
  81. * Constructor for layout.
  82. **/
  83. LOG4C_API log4c_layout_t* log4c_layout_new(const TCHAR* a_name);
  84. /**
  85. * Destructor for layout.
  86. **/
  87. LOG4C_API void log4c_layout_delete(log4c_layout_t* a_layout);
  88. /**
  89. * @param a_layout the log4c_layout_t object
  90. * @return the layout name
  91. **/
  92. LOG4C_API const TCHAR* log4c_layout_get_name(const log4c_layout_t* a_layout);
  93. /**
  94. * @param a_layout the log4c_layout_t object
  95. * @return a log4c_layout_type_t object
  96. **/
  97. LOG4C_API const log4c_layout_type_t* log4c_layout_get_type(const log4c_layout_t* a_layout);
  98. /**
  99. * sets the layout type
  100. *
  101. * @param a_layout the log4c_layout_t object
  102. * @param a_type the new layout type
  103. * @return the previous layout type
  104. *
  105. **/
  106. LOG4C_API const log4c_layout_type_t* log4c_layout_set_type(log4c_layout_t* a_layout,
  107. const log4c_layout_type_t* a_type);
  108. /**
  109. * @param a_layout the log4c_layout_t object
  110. * @return the layout user data
  111. **/
  112. LOG4C_API void* log4c_layout_get_udata(const log4c_layout_t* a_layout);
  113. /**
  114. * sets the layout user data
  115. *
  116. * @param a_layout the log4c_layout_t object
  117. * @param a_udata the new layout user data
  118. * @return the previous layout user data
  119. **/
  120. LOG4C_API void* log4c_layout_set_udata(log4c_layout_t* a_layout, void* a_udata);
  121. /**
  122. * format a log4c_logging_event events to a string.
  123. *
  124. * @param a_layout the log4c_layout_t object
  125. * @param a_event a logging_event_t object
  126. * @returns an appendable string.
  127. **/
  128. LOG4C_API const TCHAR* log4c_layout_format(const log4c_layout_t* a_layout,const log4c_logging_event_t* a_event);
  129. /**
  130. * prints the layout on a stream
  131. * @param a_layout the log4c_layout_t object
  132. * @param a_stream the stream
  133. **/
  134. LOG4C_API void log4c_layout_print(const log4c_layout_t* a_layout, FILE* a_stream);
  135. /**
  136. * prints all the current registered layout types on a stream
  137. *
  138. * @param fp the stream
  139. **/
  140. LOG4C_API void log4c_layout_types_print(FILE *fp);
  141. /** 删除本layout.c文件中定义的全局和静态的指针指向的内存,防止内存泄漏
  142. 如:
  143. 1.gs_types.
  144. 2.
  145. @return void.
  146. 作者:jesse 日期:2008.09.08
  147. */
  148. LOG4C_API void log4c_layout_delete_global();
  149. /**
  150. * Helper macro to define static layout types.
  151. *
  152. * @param a_type the log4c_layout_type_t object to define
  153. * @warning needs GCC support: otherwise this macro does nothing
  154. * @deprecated This macro, and the static initialialization
  155. * of layouts in general, is deprecated. Use rather
  156. * the log4c_layout_type_set() function to initialize your appenders
  157. * before calling log4c_init()
  158. **/
  159. #ifdef __GNUC__
  160. # define log4c_layout_type_define(a_type) \
  161. typedef int log4c_layout_type_define_##a_type __attribute__((deprecated)); \
  162. static log4c_layout_type_define_##a_type __unsused_var __attribute__((unused));
  163. #else
  164. # define log4c_layout_type_define(a_type)
  165. #endif
  166. /**
  167. * @internal
  168. **/
  169. struct __sd_factory;
  170. LOG4C_API struct __sd_factory* log4c_layout_factory;
  171. __LOG4C_END_DECLS
  172. #endif