|
|
|||
File indexing completed on 2026-01-08 10:33:34
0001 #ifndef __XRDSSILOGGER_HH__ 0002 #define __XRDSSILOGGER_HH__ 0003 /******************************************************************************/ 0004 /* */ 0005 /* X r d S s i L o g g e r . h h */ 0006 /* */ 0007 /* (c) 2013 by the Board of Trustees of the Leland Stanford, Jr., University */ 0008 /* Produced by Andrew Hanushevsky for Stanford University under contract */ 0009 /* DE-AC02-76-SFO0515 with the Deprtment of Energy */ 0010 /* */ 0011 /* This file is part of the XRootD software suite. */ 0012 /* */ 0013 /* XRootD is free software: you can redistribute it and/or modify it under */ 0014 /* the terms of the GNU Lesser General Public License as published by the */ 0015 /* Free Software Foundation, either version 3 of the License, or (at your */ 0016 /* option) any later version. */ 0017 /* */ 0018 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */ 0019 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */ 0020 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */ 0021 /* License for more details. */ 0022 /* */ 0023 /* You should have received a copy of the GNU Lesser General Public License */ 0024 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */ 0025 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */ 0026 /* */ 0027 /* The copyright holder's institutional names and contributor's names may not */ 0028 /* be used to endorse or promote products derived from this software without */ 0029 /* specific prior written permission of the institution or contributor. */ 0030 /******************************************************************************/ 0031 0032 #include <cstdarg> 0033 0034 //----------------------------------------------------------------------------- 0035 //! The XrdSsiLogger object is used to route messages to the default log file. 0036 //----------------------------------------------------------------------------- 0037 0038 struct iovec; 0039 0040 class XrdSsiLogger 0041 { 0042 public: 0043 0044 //----------------------------------------------------------------------------- 0045 //! Insert a space delimited error message into the log file. 0046 //! 0047 //! @param pfx !0 -> the text to prefix the message; the message is formed as 0048 //! <timestamp> pfx: txt1 [txt2] [txt3]\n 0049 //! pfx =0 -> add message to the log without a time stamp or prefix. 0050 //! @param txt1,txt2,txt3 the message to be added to the log. 0051 //----------------------------------------------------------------------------- 0052 0053 static void Msg(const char *pfx, const char *txt1, 0054 const char *txt2=0, const char *txt3=0); 0055 0056 //----------------------------------------------------------------------------- 0057 //! Insert a formated error message into the log file using variable args. 0058 //! 0059 //! @param pfx !0 -> the text to prefix the message; the message is formed as 0060 //! <timestamp> <pfx>: <formated_text>\n 0061 //! pfx =0 -> add message to the log without a time stamp or prefix. 0062 //! @param fmt the message formatting template (i.e. sprintf format). Note 0063 //! that a newline character is always appended to the message. 0064 //! @param ... the arguments that should be used with the template. The 0065 //! formatted message is truncated at 2048 bytes. 0066 //----------------------------------------------------------------------------- 0067 0068 static void Msgf(const char *pfx, const char *fmt, ...); 0069 0070 //----------------------------------------------------------------------------- 0071 //! Insert a formated error message into the log file using a va_list. 0072 //! 0073 //! @param pfx !0 -> the text to prefix the message; the message is formed as 0074 //! <timestamp> <pfx>: <formated_text>\n 0075 //! pfx =0 -> add message to the log without a time stamp or prefix. 0076 //! @param fmt the message formatting template (i.e. sprintf format). Note 0077 //! that a newline character is always appended to the message. 0078 //! @param aP the arguments that should be used with the template. The 0079 //! formatted message is truncated at 2048 bytes. 0080 //----------------------------------------------------------------------------- 0081 0082 static void Msgv(const char *pfx, const char *fmt, va_list aP); 0083 0084 //----------------------------------------------------------------------------- 0085 //! Insert a formated error message into the log file using a iovec. 0086 //! 0087 //! @param iovP pointer to an iovec that contains the message. 0088 //! that a newline character is always appended to the message. 0089 //! @param iovN the number of elements in the iovec. 0090 //----------------------------------------------------------------------------- 0091 0092 static void Msgv(struct iovec *iovP, int iovN); 0093 0094 //----------------------------------------------------------------------------- 0095 //! Set a message callback function for messages issued via this object. This 0096 //! method should be called during static initialization (this means the call 0097 //! needs to occur at global scope). 0098 //! 0099 //! @param mCB Reference to the message callback function as defined by 0100 //! the typedef MCB_t. 0101 //! @param mcbt Specifies the type of callback being set, as follows: 0102 //! mcbAll - callback for client-side and server-side logging. 0103 //! mcbClient - Callback for client-side logging. 0104 //! mcbServer - Callback for server-side logging. 0105 //! 0106 //! @return bool A value of true indicates success, otherwise false returned. 0107 //! The return value can generally be ignored and is provided as 0108 //! a means to call this method via dynamic global initialization. 0109 //----------------------------------------------------------------------------- 0110 0111 typedef void (MCB_t)(struct timeval const &mtime, //!< TOD of message 0112 unsigned long tID, //!< Thread issuing msg 0113 const char *msg, //!< Message text 0114 int mlen); //!< Length of message text 0115 0116 enum mcbType {mcbAll=0, mcbClient, mcbServer}; 0117 0118 static bool SetMCB(MCB_t &mcbP, mcbType mcbt=mcbAll); 0119 0120 //----------------------------------------------------------------------------- 0121 //! Define helper functions to allow std::ostream std::cerr output to appear in the log. 0122 //! The following two functions are used with the macros below. 0123 //! The SSI_LOG macro preceedes the message with a time stamp; SSI_SAY does not. 0124 //! The std::endl std::ostream output item is automatically added to all output! 0125 //----------------------------------------------------------------------------- 0126 0127 #define SSI_LOG(x) {std::cerr <<XrdSSiLogger::TBeg() <<x; XrdSsiLogger::TEnd();} 0128 #define SSI_SAY(x) {XrdSSiLogger::TBeg();std::cerr <<x; XrdSsiLogger::TEnd();} 0129 0130 static const char *TBeg(); 0131 static void TEnd(); 0132 0133 //----------------------------------------------------------------------------- 0134 //! Constructor and destructor 0135 //----------------------------------------------------------------------------- 0136 0137 XrdSsiLogger() {} 0138 ~XrdSsiLogger() {} 0139 }; 0140 0141 /******************************************************************************/ 0142 /* S e r v e r - S i d e L o g g i n g C a l l b a c k */ 0143 /******************************************************************************/ 0144 0145 //----------------------------------------------------------------------------- 0146 //! To establish a log message callback to route messages to you own logging 0147 //! framework, you normally use the SetMCB() method. This is called at part of 0148 //! your shared library initialization at load time (i.e. SetMCB() is called at 0149 //! global scope). If this is not convenient on the server-side you can use 0150 //! the following alternative; include the following definition at file level: 0151 //! 0152 //! XrdSsiLogger::MCB_t *XrdSsiLoggerMCB = &<your_log_function> 0153 //! 0154 //! For instance: 0155 //! 0156 //! void LogMsg(struct timeval const &mtime, unsigned long tID, 0157 //! const char *msg, int mlen) {...} 0158 //! 0159 //! XrdSsiLogger::MCB_t *XrdSsiLoggerMCB = &LogMsg; 0160 //----------------------------------------------------------------------------- 0161 #endif
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|