logsys_overview.8 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. .\"/*
  2. .\" * Copyright (c) 2007-2009 Red Hat, Inc.
  3. .\" *
  4. .\" * All rights reserved.
  5. .\" *
  6. .\" * Author: Steven Dake (sdake@redhat.com)
  7. .\" * Author: Fabio M. Di Nitto (fdinitto@redhat.com)
  8. .\" *
  9. .\" * This software licensed under BSD license, the text of which follows:
  10. .\" *
  11. .\" * Redistribution and use in source and binary forms, with or without
  12. .\" * modification, are permitted provided that the following conditions are met:
  13. .\" *
  14. .\" * - Redistributions of source code must retain the above copyright notice,
  15. .\" * this list of conditions and the following disclaimer.
  16. .\" * - Redistributions in binary form must reproduce the above copyright notice,
  17. .\" * this list of conditions and the following disclaimer in the documentation
  18. .\" * and/or other materials provided with the distribution.
  19. .\" * - Neither the name of the MontaVista Software, Inc. nor the names of its
  20. .\" * contributors may be used to endorse or promote products derived from this
  21. .\" * software without specific prior written permission.
  22. .\" *
  23. .\" * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  24. .\" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  25. .\" * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  26. .\" * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  27. .\" * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  28. .\" * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  29. .\" * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  30. .\" * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  31. .\" * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  32. .\" * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  33. .\" * THE POSSIBILITY OF SUCH DAMAGE.
  34. .\" */
  35. .TH LOGSYS_OVERVIEW 8 2009-06-16 "corosync Man Page" "Corosync Cluster Engine Programmer's Manual"
  36. .SH NAME
  37. logsys_overview \- Logsys Library Overview
  38. .SH OVERVIEW
  39. The logsys library provides a generically usable logging and tracing system for
  40. use by applications. It supports many features including:
  41. .PP
  42. Configurable subsystem logging or single system logging
  43. .PP
  44. Threaded non-blocking logging of log output data for better non-blocking performance
  45. .PP
  46. Support for 8 tracing levels and tracing the entering and leaving of functions
  47. .PP
  48. Declaration of logging system or subsystem without calling any functions
  49. .PP
  50. Dynamic reconfiguration of the logging system parameters
  51. .PP
  52. Logging to syslog, file, stderr.
  53. .SH Declaration of the System logger
  54. The logsys library is initially configured by including logsys.h and declaring
  55. a logger. Once the logger is declared, optional subsystem loggers can be
  56. declared in every file.
  57. The definition LOGSYS_DECLARE_SYSTEM is placed after the include section of one
  58. C file in the application. This declaration creates a constructor function
  59. which will be called automatically before main() is executed. This technique
  60. avoids the need for calling any setup functions in short applications that don't
  61. require it and enables full logging capabilities before any application code is
  62. executed.
  63. #define LOGSYS_DECLARE_SYSTEM (name, mode, debug, file, file_priority,
  64. syslog_facility, syslog_priority, format, fltsize)
  65. The name parameter is the name of the application or system.
  66. The mode parameter is the logging mode of the system.
  67. The following modes can be configured by logically ORing these flags:
  68. LOGSYS_MODE_OUTPUT_FILE: Output all log data to the file parameter of this declaration
  69. LOGSYS_MODE_OUTPUT_STDERR: Output all log data to the stderr descriptor
  70. LOGSYS_MODE_OUTPUT_SYSLOG: Output all log data to syslog using a non-blocking thread
  71. LOGSYS_MODE_FORK: This flags tells logsys to queue all data untill the application
  72. has forked. The application is then responsible to call logsys_fork_completed to flush
  73. the queue and start logging.
  74. LOGSYS_MODE_THREADED: Starts a separate thread to handle non-blocking logging operations.
  75. If this flag is not specified, the logging operations are blocking.
  76. The debug parameter, if enabled, turns off all messages priority filtering, recording
  77. everything everywhere.
  78. The file parameter specifies the filename that should be used to log messages.
  79. This parameter may be NULL and no log file will be created.
  80. The file_priority parameter specifies the message priority that should be logged to file.
  81. The syslog_facility parameter is the syslog facility that should be used when logging
  82. messages.
  83. The syslog_priority, similar to file_priority, specifies the message priority that should be logged to
  84. syslog.
  85. The format parameter allows to set custom output format.
  86. Set to NULL to use built-in default.
  87. The fltsize parameter specifies the flight recorder buffer size in bytes. The requested value
  88. is increased by the size of 2 unsigned ints and rounded to the next PAGE_SIZE.
  89. An example declaration would be:
  90. #include <corosync/logsys.h>
  91. ... (other #includes)
  92. LOGSYS_DECLARE_SYSTEM ("test", /* name */
  93. LOGSYS_MODE_OUTPUT_STDERR | LOGSYS_MODE_THREADED, /* mode */
  94. 0, /* debug */
  95. NULL, /* logfile path */
  96. LOGSYS_LEVEL_INFO, /* logfile_priority */
  97. LOG_DAEMON, /* syslog facility */
  98. LOGSYS_LEVEL_INFO, /* syslog level */
  99. NULL, /* use default format */
  100. 1000000); /* flight recorder size */
  101. .SH Declaration of subsystems
  102. The logsys library supports the logging of information to one main system or
  103. subsystem. This is specified in each individual object C file in the system
  104. and it is entirely optional.
  105. An example:
  106. LOGSYS_DECLARE_SUBSYS ("subsystest");
  107. It is possible to use the same subsystem name in separate object files.
  108. In this case, the individual logging parameters for those subsystem identifier
  109. will be used.
  110. A newly created subsystem inherits the system configuration at the time of
  111. creation.
  112. It is possible to override every configuration option on a subsystem base
  113. throught the configuration API.
  114. .SH Logging Messages
  115. The definition log_printf is used to log information to the log. It works
  116. in a similiar fashion to printf, except it has a first parameter of level
  117. which may be the following:
  118. LOGSYS_LEVEL_EMERG
  119. LOGSYS_LEVEL_ALERT
  120. LOGSYS_LEVEL_CRIT
  121. LOGSYS_LEVEL_ERR
  122. LOGSYS_LEVEL_WARNING
  123. LOGSYS_LEVEL_NOTICE
  124. LOGSYS_LEVEL_INFO
  125. LOGSYS_LEVEL_DEBUG
  126. An example of using log_printf would be
  127. log_printf (LOGSYS_LEVEL_EMERG, "This is an emergency %s value %d\n", string, value);
  128. Tracing of functions can be done using ENTER(), LEAVE();
  129. An example of using ENTER is
  130. void function (char *name) {
  131. ENTER();
  132. ... function contents ...
  133. LEAVE();
  134. }
  135. Individual tracing levels are supported through the macros
  136. TRACE1(format, args)
  137. TRACE2(format, args)
  138. ..
  139. TRACE8(format, args)
  140. An example of using TRACE is
  141. char *name = "test";
  142. TRACE7 ("This is a trace 7 log with name %s\n", name);
  143. Note that ENTER/LEAVE/TRACE* calls are recorded only in the flight recorder.
  144. .SH "SEE ALSO"
  145. .BR logsys_fork_completed (3),
  146. .BR logsys_atexit (3),
  147. .BR logsys_log_rec_store (3),
  148. .BR logsys_format_set (3),
  149. .BR logsys_format_get (3),
  150. .BR logsys_config_mode_set (3),
  151. .BR logsys_config_file_set (3),
  152. .BR logsys_config_syslog_facility_set (3),
  153. .BR logsys_config_syslog_facility_get (3),
  154. .BR logsys_config_mode_set (3),
  155. .BR logsys_config_mode_get (3),
  156. .BR logsys_config_file_set (3),
  157. .BR logsys_config_logfile_priority_set (3),
  158. .BR logsys_config_debug_set (3),
  159. .BR logsys_facility_id_get (3),
  160. .BR logsys_facility_name_get (3),
  161. .BR logsys_priority_id_get (3),
  162. .BR logsys_priority_name_get (3),
  163. .PP