You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

190 lines
7.2 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  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. {
  32. namespace log
  33. {
  34. /// Type of a channel package
  35. typedef uint32_t level;
  36. /// Package of values for hinting at the nature of a given logger.
  37. /**
  38. * Used by the library to signal to the logging class a hint that it can use to
  39. * set itself up. For example, the `access` hint indicates that it is an access
  40. * log that might be suitable for being printed to an access log file or to cout
  41. * whereas `error` might be suitable for an error log file or cerr.
  42. */
  43. struct channel_type_hint
  44. {
  45. /// Type of a channel type hint value
  46. typedef uint32_t value;
  47. /// No information
  48. static const value none = 0;
  49. /// Access log
  50. static const value access = 1;
  51. /// Error log
  52. static const value error = 2;
  53. };
  54. /// Package of log levels for logging errors
  55. struct elevel
  56. {
  57. /// Special aggregate value representing "no levels"
  58. static const level none = 0x0;
  59. /// Low level debugging information (warning: very chatty)
  60. static const level devel = 0x1;
  61. /// Information about unusual system states or other minor internal library
  62. /// problems, less chatty than devel.
  63. static const level library = 0x2;
  64. /// Information about minor configuration problems or additional information
  65. /// about other warnings.
  66. static const level info = 0x4;
  67. /// Information about important problems not severe enough to terminate
  68. /// connections.
  69. static const level warn = 0x8;
  70. /// Recoverable error. Recovery may mean cleanly closing the connection with
  71. /// an appropriate error code to the remote endpoint.
  72. static const level rerror = 0x10;
  73. /// Unrecoverable error. This error will trigger immediate unclean
  74. /// termination of the connection or endpoint.
  75. static const level fatal = 0x20;
  76. /// Special aggregate value representing "all levels"
  77. static const level all = 0xffffffff;
  78. /// Get the textual name of a channel given a channel id
  79. /**
  80. * The id must be that of a single channel. Passing an aggregate channel
  81. * package results in undefined behavior.
  82. *
  83. * @param channel The channel id to look up.
  84. *
  85. * @return The name of the specified channel.
  86. */
  87. static const char * channel_name(level channel)
  88. {
  89. switch (channel)
  90. {
  91. case devel : return "devel";
  92. case library: return "library";
  93. case info : return "info";
  94. case warn : return "warning";
  95. case rerror : return "error";
  96. case fatal : return "fatal";
  97. default : return "unknown";
  98. }
  99. }
  100. };
  101. /// Package of log levels for logging access events
  102. struct alevel
  103. {
  104. /// Special aggregate value representing "no levels"
  105. static const level 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 const level connect = 0x1;
  113. /// One line for each closed connection. Includes closing codes and reasons.
  114. static const level disconnect = 0x2;
  115. /// One line per control frame
  116. static const level control = 0x4;
  117. /// One line per frame, includes the full frame header
  118. static const level frame_header = 0x8;
  119. /// One line per frame, includes the full message payload (warning: chatty)
  120. static const level frame_payload = 0x10;
  121. /// Reserved
  122. static const level message_header = 0x20;
  123. /// Reserved
  124. static const level message_payload = 0x40;
  125. /// Reserved
  126. static const level endpoint = 0x80;
  127. /// Extra information about opening handshakes
  128. static const level debug_handshake = 0x100;
  129. /// Extra information about closing handshakes
  130. static const level debug_close = 0x200;
  131. /// Development messages (warning: very chatty)
  132. static const level devel = 0x400;
  133. /// Special channel for application specific logs. Not used by the library.
  134. static const level app = 0x800;
  135. /// Access related to HTTP requests
  136. static const level http = 0x1000;
  137. /// One line for each failed WebSocket connection with details
  138. static const level fail = 0x2000;
  139. /// Aggregate package representing the commonly used core access channels
  140. /// Connect, Disconnect, Fail, and HTTP
  141. static const level access_core = 0x00003003;
  142. /// Special aggregate value representing "all levels"
  143. static const level 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 const char * channel_name(level channel)
  155. {
  156. switch (channel)
  157. {
  158. case connect : return "connect";
  159. case disconnect : return "disconnect";
  160. case control : return "control";
  161. case frame_header : return "frame_header";
  162. case frame_payload : return "frame_payload";
  163. case message_header : return "message_header";
  164. case message_payload: return "message_payload";
  165. case endpoint : return "endpoint";
  166. case debug_handshake: return "debug_handshake";
  167. case debug_close : return "debug_close";
  168. case devel : return "devel";
  169. case app : return "application";
  170. case http : return "http";
  171. case fail : return "fail";
  172. default : return "unknown";
  173. }
  174. }
  175. };
  176. } // namespace log
  177. } // namespace websocketpp
  178. #endif // WEBSOCKETPP_LOGGER_LEVELS_HPP