levels.hpp 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. /*
  2. * Copyright (c) 2014, Peter Thorson. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions are met:
  6. * * Redistributions of source code must retain the above copyright
  7. * notice, this list of conditions and the following disclaimer.
  8. * * Redistributions in binary form must reproduce the above copyright
  9. * notice, this list of conditions and the following disclaimer in the
  10. * documentation and/or other materials provided with the distribution.
  11. * * Neither the name of the WebSocket++ Project nor the
  12. * names of its contributors may be used to endorse or promote products
  13. * derived from this software without specific prior written permission.
  14. *
  15. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  16. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  18. * ARE DISCLAIMED. IN NO EVENT SHALL PETER THORSON BE LIABLE FOR ANY
  19. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  20. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  21. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  22. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  23. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  24. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. *
  26. */
  27. #ifndef WEBSOCKETPP_LOGGER_LEVELS_HPP
  28. #define WEBSOCKETPP_LOGGER_LEVELS_HPP
  29. #include <websocketpp/common/stdint.hpp>
  30. namespace websocketpp {
  31. namespace log {
  32. /// Type of a channel package
  33. typedef uint32_t level;
  34. /// Package of values for hinting at the nature of a given logger.
  35. /**
  36. * Used by the library to signal to the logging class a hint that it can use to
  37. * set itself up. For example, the `access` hint indicates that it is an access
  38. * log that might be suitable for being printed to an access log file or to cout
  39. * whereas `error` might be suitable for an error log file or cerr.
  40. */
  41. struct channel_type_hint {
  42. /// Type of a channel type hint value
  43. typedef uint32_t value;
  44. /// No information
  45. static value const none = 0;
  46. /// Access log
  47. static value const access = 1;
  48. /// Error log
  49. static value const error = 2;
  50. };
  51. /// Package of log levels for logging errors
  52. struct elevel {
  53. /// Special aggregate value representing "no levels"
  54. static level const none = 0x0;
  55. /// Low level debugging information (warning: very chatty)
  56. static level const devel = 0x1;
  57. /// Information about unusual system states or other minor internal library
  58. /// problems, less chatty than devel.
  59. static level const library = 0x2;
  60. /// Information about minor configuration problems or additional information
  61. /// about other warnings.
  62. static level const info = 0x4;
  63. /// Information about important problems not severe enough to terminate
  64. /// connections.
  65. static level const warn = 0x8;
  66. /// Recoverable error. Recovery may mean cleanly closing the connection with
  67. /// an appropriate error code to the remote endpoint.
  68. static level const rerror = 0x10;
  69. /// Unrecoverable error. This error will trigger immediate unclean
  70. /// termination of the connection or endpoint.
  71. static level const fatal = 0x20;
  72. /// Special aggregate value representing "all levels"
  73. static level const all = 0xffffffff;
  74. /// Get the textual name of a channel given a channel id
  75. /**
  76. * The id must be that of a single channel. Passing an aggregate channel
  77. * package results in undefined behavior.
  78. *
  79. * @param channel The channel id to look up.
  80. *
  81. * @return The name of the specified channel.
  82. */
  83. static char const * channel_name(level channel) {
  84. switch(channel) {
  85. case devel:
  86. return "devel";
  87. case library:
  88. return "library";
  89. case info:
  90. return "info";
  91. case warn:
  92. return "warning";
  93. case rerror:
  94. return "error";
  95. case fatal:
  96. return "fatal";
  97. default:
  98. return "unknown";
  99. }
  100. }
  101. };
  102. /// Package of log levels for logging access events
  103. struct alevel {
  104. /// Special aggregate value representing "no levels"
  105. static level const none = 0x0;
  106. /// Information about new connections
  107. /**
  108. * One line for each new connection that includes a host of information
  109. * including: the remote address, websocket version, requested resource,
  110. * http code, remote user agent
  111. */
  112. static level const connect = 0x1;
  113. /// One line for each closed connection. Includes closing codes and reasons.
  114. static level const disconnect = 0x2;
  115. /// One line per control frame
  116. static level const control = 0x4;
  117. /// One line per frame, includes the full frame header
  118. static level const frame_header = 0x8;
  119. /// One line per frame, includes the full message payload (warning: chatty)
  120. static level const frame_payload = 0x10;
  121. /// Reserved
  122. static level const message_header = 0x20;
  123. /// Reserved
  124. static level const message_payload = 0x40;
  125. /// Reserved
  126. static level const endpoint = 0x80;
  127. /// Extra information about opening handshakes
  128. static level const debug_handshake = 0x100;
  129. /// Extra information about closing handshakes
  130. static level const debug_close = 0x200;
  131. /// Development messages (warning: very chatty)
  132. static level const devel = 0x400;
  133. /// Special channel for application specific logs. Not used by the library.
  134. static level const app = 0x800;
  135. /// Access related to HTTP requests
  136. static level const http = 0x1000;
  137. /// One line for each failed WebSocket connection with details
  138. static level const fail = 0x2000;
  139. /// Aggregate package representing the commonly used core access channels
  140. /// Connect, Disconnect, Fail, and HTTP
  141. static level const access_core = 0x00003003;
  142. /// Special aggregate value representing "all levels"
  143. static level const all = 0xffffffff;
  144. /// Get the textual name of a channel given a channel id
  145. /**
  146. * Get the textual name of a channel given a channel id. The id must be that
  147. * of a single channel. Passing an aggregate channel package results in
  148. * undefined behavior.
  149. *
  150. * @param channel The channelid to look up.
  151. *
  152. * @return The name of the specified channel.
  153. */
  154. static char const * channel_name(level channel) {
  155. switch(channel) {
  156. case connect:
  157. return "connect";
  158. case disconnect:
  159. return "disconnect";
  160. case control:
  161. return "control";
  162. case frame_header:
  163. return "frame_header";
  164. case frame_payload:
  165. return "frame_payload";
  166. case message_header:
  167. return "message_header";
  168. case message_payload:
  169. return "message_payload";
  170. case endpoint:
  171. return "endpoint";
  172. case debug_handshake:
  173. return "debug_handshake";
  174. case debug_close:
  175. return "debug_close";
  176. case devel:
  177. return "devel";
  178. case app:
  179. return "application";
  180. case http:
  181. return "http";
  182. case fail:
  183. return "fail";
  184. default:
  185. return "unknown";
  186. }
  187. }
  188. };
  189. } // logger
  190. } // websocketpp
  191. #endif //WEBSOCKETPP_LOGGER_LEVELS_HPP