logsys_overview.8 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. .\"/*
  2. .\" * Copyright (c) 2007 Red Hat, Inc.
  3. .\" *
  4. .\" * All rights reserved.
  5. .\" *
  6. .\" * Author: Steven Dake (sdake@redhat.com)
  7. .\" *
  8. .\" * This software licensed under BSD license, the text of which follows:
  9. .\" *
  10. .\" * Redistribution and use in source and binary forms, with or without
  11. .\" * modification, are permitted provided that the following conditions are met:
  12. .\" *
  13. .\" * - Redistributions of source code must retain the above copyright notice,
  14. .\" * this list of conditions and the following disclaimer.
  15. .\" * - Redistributions in binary form must reproduce the above copyright notice,
  16. .\" * this list of conditions and the following disclaimer in the documentation
  17. .\" * and/or other materials provided with the distribution.
  18. .\" * - Neither the name of the MontaVista Software, Inc. nor the names of its
  19. .\" * contributors may be used to endorse or promote products derived from this
  20. .\" * software without specific prior written permission.
  21. .\" *
  22. .\" * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  23. .\" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. .\" * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  25. .\" * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  26. .\" * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  27. .\" * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  28. .\" * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  29. .\" * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  30. .\" * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  31. .\" * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  32. .\" * THE POSSIBILITY OF SUCH DAMAGE.
  33. .\" */
  34. .TH LOGSYS_OVERVIEW 8 2007-05-15 "corosync Man Page" "Corosync Cluster Engine Programmer's Manual"
  35. .SH OVERVIEW
  36. The logsys library provides a generically usable logging and tracing system for
  37. use by applications. It supports many features including:
  38. .PP
  39. Configurable subsystem logging or single system logging
  40. .PP
  41. Threaded non-blocking logging of log output data for better non-blocking performance
  42. .PP
  43. Support for 8 tracing levels and tracing the entering and leaving of functions
  44. .PP
  45. Declaration of logging system or subsystem without calling any functions
  46. .PP
  47. Dynamic reconfiguration of the logging system parameters
  48. .PP
  49. Logging to syslog, file, stderr.
  50. .SH Declaration of the System logger
  51. The logsys library is initially configured by including logsys.h and declaring
  52. a logger. Once the logger is declared either a subsystem logger or nosubsystem
  53. logger is declared in every file.
  54. The definition LOGSYS_DECLARE_SYSTEM is placed after the include section of one
  55. C file in the application. This declaration creates a constructor function
  56. which will be called automatically. This technique avoids the need for calling
  57. any setup functions in short applications that don't require it.
  58. #define LOGSYS_DECLARE_SYSTEM(name,mode,file,facility)
  59. The name parameter is the name of the application.
  60. The mode parameter is the logging mode of the system. The following modes
  61. can be configured by logically ORing these flags:
  62. LOG_MODE_OUTPUT_FILE: Output all log data to the file parameter of this declaration
  63. LOG_MODE_OUTPUT_STDERR: Output all log data to the stderr descriptor
  64. LOG_MODE_OUTPUT_SYSLOG_THREADED: Output all log data to syslog using a non-blocking thread
  65. LOG_MODE_OUTPUT_SYSLOG_LOSSY: Output all log data without using a thread but potentially losing data. This mode is not yet implemented.
  66. LOG_MODE_OUTPUT_SYSLOG_BLOCKING: Output all log data without using a thread and potentially blocking at each syslog call.
  67. LOG_MODE_DISPLAY_PRIORITY: Output the priority of the log entry in the message contents. This mode is currently not implemented.
  68. LOG_MODE_DISPLAY_FILELINE: Output the file and line at which the log message was created.
  69. LOG_MODE_SHORT_FILELINE: When using LOG_DEBUG level or LOG_MODE_DISPLAY_FILELINE, typically the absolute path to the file (derived at compile-time) is displayed. Enabling this flag ensures that only the filename and line are displayed.
  70. LOG_MODE_DISPLAY_TIMESTAMP: Output the timestamp of the message.
  71. LOG_MODE_BUFFER_BEFORE_CONFIG: This mode is used to buffer log messages before logsys_mode_config is called. This is useful in applications in which the logging file isn't known before the application is compiled and must be set dynamically. It is also useful when an application calls fork to disconnect the local tty and should hold logging of messages until after the fork.
  72. LOG_MODE_FLUSH_AFTER_CONFIG: This mode is used to flush any buffered messages when the LOG_MODE_BUFFER_BEFORE_CONFIG declaration is specified in the declaration of the logger.
  73. The file parameter specifies the filename that should be used to log messages. This parameter may be NULL if LOG_MODE_OUTPUT_FILE is not specified.
  74. The facility parameter is the syslog facility that should be used when logging
  75. messages.
  76. LOG_MODE_NOSUBSYS: Enabling this mode removes the subsystem tag from the beginning of the log lines. This is not recommended for programs which have multiple subsystems.
  77. LOG_MODE_FILTER_DEBUG_FROM_SYSLOG: Enabling this mode will stop debug messages from being sent to syslog.
  78. An example declaration would be:
  79. #include <corosync/logsys.h>
  80. ... (other #includes)
  81. LOGSYS_DECLARE_SYSTEM ("my_example_app",
  82. LOG_MODE_OUTPUT_STDERR | LOG_MODE_OUTPUT_SYSLOG_THREADED | LOG_MODE_OUTPUT_FILE,
  83. "/tmp/log",
  84. LOG_DAEMON);
  85. This would output any logging messages to stderr, syslog, and the file /tmp/log.
  86. .SH Declaration of subsystems or no subsystems
  87. The logsys library supports the logging of information to one main system or
  88. subsystem. This is specified in each individual object file in the system.
  89. if no subsystems are desired, The define LOGSYS_DECLARE_NOSUBSYS should be
  90. declared for every object file in the system. These object files are usually C
  91. files.
  92. An example of using this would be
  93. LOGSYS_DECLARE_NOSUBSYS (LOG_LEVEL_INFO);
  94. Any messages of LOG_LEVEL_INFO priority or higher would be logged.
  95. If subsystems are desired, the define LOGSYS_DECLARE_SUBSYS should be declared
  96. for every object file in the system. It is possible to use the same subsystem
  97. name in separate object files. In this case, the individual logging parameters
  98. for those subsystem identifier will be used.
  99. An example of using this would be
  100. LOGSYS_DECLARE_SUBSYS ("SYS1", LOG_LEVEL_INFO);
  101. Any message of LOG_LEVEL_INFO priority or higher would be logged and any
  102. logging within the object file this declaration is specified within will be
  103. logged to the SYS1 subsystem identifier.
  104. .SH Logging Messages
  105. The definition log_printf is used to log information to the log. It works
  106. in a similiar fashion to printf, except it has a first parameter of level
  107. which may be the following:
  108. LOG_EMERG
  109. LOG_ALERT
  110. LOG_CRIT
  111. LOG_ERR
  112. LOG_WARNING
  113. LOG_NOTICE
  114. LOG_INFO
  115. LOG_DEBUG
  116. An example of using log_printf would be
  117. log_printf (LOG_EMERG, "This is an emergency %s value %d\n", string, value);
  118. Tracing of functions can be done using ENTER_VOID() or ENTER (format, args) LEAVE_VOID() or LEAVE (format, args);
  119. An exmaple of using ENTER_VOID is
  120. void funtion (void) {
  121. ENTER_VOID();
  122. ... function contents ...
  123. LEAVE_VOID();
  124. }
  125. An example of using ENTER is
  126. void function (char *name) {
  127. ENTER ("The name is %s\n", name);
  128. ... function contents ...
  129. LEAVE ("Bye\n");
  130. }
  131. Individual tracing levels are supported through the macros
  132. TRACE1(format, args)
  133. TRACE2(format, args)
  134. ..
  135. TRACE8(format, args)
  136. An example of using TRACE is
  137. char *name = "test";
  138. TRACE7 ("This is a trace 7 log with name %s\n", name);
  139. .SH "SEE ALSO"
  140. .BR logsys_config_mode_set (3),
  141. .BR logsys_config_file_set (3),
  142. .BR logsys_config_facility_set (3),
  143. .BR logsys_config_facility_set (3),
  144. .BR logsys_config_priority_set (3),
  145. .BR logsys_config_subsys_set (3),
  146. .BR logsys_config_subsys_get (3),
  147. .BR logsys_facility_id_get (3),
  148. .BR logsys_priority_id_get (3),
  149. .BR logsys_flush (3),
  150. .BR logsys_atsegv (3),
  151. .PP