logsys_overview.8 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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 "openais Man Page" "Openais 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. Declartion 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 Declartion 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 declartion 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 declartion
  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_DISPLAY_TIMESTAMP: Output the timestamp of the message.
  70. LOG_MODE_DISPLAY_DEBUG: Display debug level messages
  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 declartion is specified in the declartion 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. An example declartion would be:
  77. #include <openais/logsys.h>
  78. ... (other #includes)
  79. LOGSYS_DECLARE_SYSTEM ("my_example_app",
  80. LOG_MODE_OUTPUT_STDERR | LOG_MODE_OUTPUT_SYSLOG_THREADED | LOG_MODE_OUTPUT_FILE,
  81. "/tmp/log",
  82. LOG_DAEMON);
  83. This would output any logging messages to stderr, syslog, and the file /tmp/log.
  84. .SH Declartion of subsystems or no subsystems
  85. The logsys library supports the logging of information to one main system or
  86. subsystem. This is specified in each individual object file in the system.
  87. if no subsystems are desired, The define LOGSYS_DECLARE_NOSUBSYS should be
  88. declared for every object file in the system. These object files are usually C
  89. files.
  90. An example of using this would be
  91. LOGSYS_DECLARE_NOSUBSYS (LOG_LEVEL_INFO);
  92. Any messages of LOG_LEVEL_INFO priority or higher would be logged.
  93. If subsystems are desired, the define LOGSYS_DECLARE_SUBSYS should be declared
  94. for every object file in the system. It is possible to use the same subsystem
  95. name in separate object files. In this case, the individual logging parameters
  96. for those subsystem identifier will be used.
  97. An example of using this would be
  98. LOGSYS_DECLARE_SUBSYS ("SYS1", LOG_LEVEL_INFO);
  99. Any message of LOG_LEVEL_INFO priority or higher would be logged and any
  100. logging within the object file this declartion is specified within will be
  101. logged to the SYS1 subsystem identifier.
  102. .SH Logging Messages
  103. The definition log_printf is used to log information to the log. It works
  104. in a similiar fashion to printf, except it has a first parameter of level
  105. which may be the following:
  106. LOG_EMERG
  107. LOG_ALERT
  108. LOG_CRIT
  109. LOG_ERR
  110. LOG_WARNING
  111. LOG_NOTICE
  112. LOG_INFO
  113. LOG_DEBUG
  114. An example of using log_printf would be
  115. log_printf (LOG_EMERG, "This is an emergency %s value %d\n", string, value);
  116. Tracing of functions can be done using ENTER_VOID() or ENTER (format, args) LEAVE_VOID() or LEAVE (format, args);
  117. An exmaple of using ENTER_VOID is
  118. void funtion (void) {
  119. ENTER_VOID();
  120. ... function contents ...
  121. LEAVE_VOID();
  122. }
  123. An example of using ENTER is
  124. void function (char *name) {
  125. ENTER ("The name is %s\n", name);
  126. ... function contents ...
  127. LEAVE ("Bye\n");
  128. }
  129. Individual tracing levels are supported through the macros
  130. TRACE1(format, args)
  131. TRACE2(format, args)
  132. ..
  133. TRACE8(format, args)
  134. An example of using TRACE is
  135. char *name = "test";
  136. TRACE7 ("This is a trace 7 log with name %s\n", name);
  137. .SH "SEE ALSO"
  138. .BR logsys_config_mode_set (3),
  139. .BR logsys_config_file_set (3),
  140. .BR logsys_config_facility_set (3),
  141. .BR logsys_config_facility_set (3),
  142. .BR logsys_config_priority_set (3),
  143. .BR logsys_config_subsys_set (3),
  144. .BR logsys_config_subsys_get (3),
  145. .BR logsys_facility_id_get (3),
  146. .BR logsys_priority_id_get (3),
  147. .BR logsys_flush (3),
  148. .BR logsys_atsegv (3),
  149. .PP