xrootd
Loading...
Searching...
No Matches
XrdSysError.hh
Go to the documentation of this file.
1#ifndef __SYS_ERROR_H__
2#define __SYS_ERROR_H__
3/******************************************************************************/
4/* */
5/* X r d S y s E r r o r . h h */
6/* */
7/*(c) 2004 by the Board of Trustees of the Leland Stanford, Jr., University */
8/*Produced by Andrew Hanushevsky for Stanford University under contract */
9/* DE-AC02-76-SFO0515 with the Deprtment of Energy */
10/* */
11/* This file is part of the XRootD software suite. */
12/* */
13/* XRootD is free software: you can redistribute it and/or modify it under */
14/* the terms of the GNU Lesser General Public License as published by the */
15/* Free Software Foundation, either version 3 of the License, or (at your */
16/* option) any later version. */
17/* */
18/* XRootD is distributed in the hope that it will be useful, but WITHOUT */
19/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
20/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
21/* License for more details. */
22/* */
23/* You should have received a copy of the GNU Lesser General Public License */
24/* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
25/* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
26/* */
27/* The copyright holder's institutional names and contributor's names may not */
28/* be used to endorse or promote products derived from this software without */
29/* specific prior written permission of the institution or contributor. */
30/******************************************************************************/
31
32#include <cstdlib>
33#ifndef WIN32
34#include <unistd.h>
35#include <cstring>
36#include <strings.h>
37#else
38#include <cstring>
39#endif
40
41/******************************************************************************/
42/* o o u c _ E r r o r _ T a b l e */
43/******************************************************************************/
44
46{
47public:
48friend class XrdSysError;
49
50char *Lookup(int mnum)
51 {return (char *)(mnum < base_msgnum || mnum > last_msgnum
52 ? 0 : msg_text[mnum - base_msgnum]);
53 }
54 XrdSysError_Table(int base, int last, const char **text)
55 : next(0),
56 base_msgnum(base),
57 last_msgnum(last),
58 msg_text(text) {}
60
61private:
62XrdSysError_Table *next; // -> Next table or 0;
63int base_msgnum; // Starting message number
64int last_msgnum; // Ending message number
65const char **msg_text; // Array of message text
66};
67
68/******************************************************************************/
69/* L o g M a s k D e f i n i t i o n s */
70/******************************************************************************/
71
72const int SYS_LOG_01 = 1;
73const int SYS_LOG_02 = 2;
74const int SYS_LOG_03 = 4;
75const int SYS_LOG_04 = 8;
76const int SYS_LOG_05 = 16;
77const int SYS_LOG_06 = 32;
78const int SYS_LOG_07 = 64;
79const int SYS_LOG_08 = 128;
80// 0x00000100 to 0x0000ffff reseved for XRootD use
81// 0x00010000 to 0xffff0000 reseved for non-XRootD use
82
83/******************************************************************************/
84/* o o u c _ E r r o r */
85/******************************************************************************/
86
87class XrdSysLogger;
88
90{
91public:
92 XrdSysError(XrdSysLogger *lp, const char *ErrPrefix="sys")
93 : epfx(0),
94 epfxlen(0),
95 msgMask(-1),
96 Logger(lp)
97 { SetPrefix(ErrPrefix); }
98
100
101// addTable allows you to add a new error table for errno handling. Any
102// number of table may be added and must consist of statis message text
103// since the table are deleted but the text is not freed. Error tables
104// must be setup without multi-threading. There is only one global table.
105//
106static void addTable(XrdSysError_Table *etp) {etp->next = etab; etab = etp;}
107
108// baseFD() returns the original FD associated with this object.
109//
110int baseFD();
111
112// ec2text tyranslates an error code to the correspodning error text or returns
113// null if matching text cannot be found.
114//
115static const char *ec2text(int ecode);
116
117// Emsg() produces a message of various forms. The message is written to the
118// constructor specified file descriptor. See variations below.
119//
120// <datetime> <epfx><esfx>: error <ecode> (syser[<ecode>]); <text1> <text2>"
121// (returns abs(ecode)).
122//
123int Emsg(const char *esfx, int ecode, const char *text1, const char *text2=0);
124
125// <datetime> <epfx><esfx>: <text1> <text2> <text3>
126//
127void Emsg(const char *esfx, const char *text1,
128 const char *text2=0,
129 const char *text3=0);
130
131// <datetime> <epfx><esfx>: <text1> <text2> <text3>
132//
133inline void Log(int mask, const char *esfx,
134 const char *text1,
135 const char *text2=0,
136 const char *text3=0)
137 {if (mask & msgMask) Emsg(esfx, text1, text2, text3);}
138
139// logger() sets/returns the logger object for this message message handler.
140//
142 {XrdSysLogger *oldp = Logger;
143 if (lp) Logger = lp;
144 return oldp;
145 }
146
147// Say() route a line without timestamp or prefix
148//
149void Say(const char *text1, const char *text2=0, const char *txt3=0,
150 const char *text4=0, const char *text5=0, const char *txt6=0);
151
152// Set/Get the loging mask (only used by clients of this object)
153//
154void setMsgMask(int mask) {msgMask = mask;}
155
156int getMsgMask() {return msgMask;}
157
158// SetPrefix() dynamically changes the error prefix
159//
160inline const char *SetPrefix(const char *prefix)
161 {const char *oldpfx = epfx;
162 epfx = prefix; epfxlen = strlen(epfx);
163 return oldpfx;
164 }
165
166// TBeg() is used to start a trace on std::ostream std::cerr. The TEnd() ends the trace.
167//
168void TBeg(const char *txt1=0, const char *txt2=0, const char *txt3=0);
169void TEnd();
170
171private:
172
174const char *epfx;
178};
179#endif
const int SYS_LOG_02
Definition XrdSysError.hh:73
const int SYS_LOG_06
Definition XrdSysError.hh:77
const int SYS_LOG_07
Definition XrdSysError.hh:78
const int SYS_LOG_08
Definition XrdSysError.hh:79
const int SYS_LOG_01
Definition XrdSysError.hh:72
const int SYS_LOG_05
Definition XrdSysError.hh:76
const int SYS_LOG_04
Definition XrdSysError.hh:75
const int SYS_LOG_03
Definition XrdSysError.hh:74
Definition XrdSysError.hh:46
char * Lookup(int mnum)
Definition XrdSysError.hh:50
const char ** msg_text
Definition XrdSysError.hh:65
int base_msgnum
Definition XrdSysError.hh:63
~XrdSysError_Table()
Definition XrdSysError.hh:59
int last_msgnum
Definition XrdSysError.hh:64
XrdSysError_Table * next
Definition XrdSysError.hh:62
XrdSysError_Table(int base, int last, const char **text)
Definition XrdSysError.hh:54
Definition XrdSysError.hh:90
int Emsg(const char *esfx, int ecode, const char *text1, const char *text2=0)
void TBeg(const char *txt1=0, const char *txt2=0, const char *txt3=0)
int msgMask
Definition XrdSysError.hh:176
XrdSysError(XrdSysLogger *lp, const char *ErrPrefix="sys")
Definition XrdSysError.hh:92
const char * epfx
Definition XrdSysError.hh:174
static void addTable(XrdSysError_Table *etp)
Definition XrdSysError.hh:106
void Say(const char *text1, const char *text2=0, const char *txt3=0, const char *text4=0, const char *text5=0, const char *txt6=0)
void setMsgMask(int mask)
Definition XrdSysError.hh:154
~XrdSysError()
Definition XrdSysError.hh:99
const char * SetPrefix(const char *prefix)
Definition XrdSysError.hh:160
static const char * ec2text(int ecode)
int getMsgMask()
Definition XrdSysError.hh:156
XrdSysLogger * Logger
Definition XrdSysError.hh:177
static XrdSysError_Table * etab
Definition XrdSysError.hh:173
int epfxlen
Definition XrdSysError.hh:175
XrdSysLogger * logger(XrdSysLogger *lp=0)
Definition XrdSysError.hh:141
void Emsg(const char *esfx, const char *text1, const char *text2=0, const char *text3=0)
void Log(int mask, const char *esfx, const char *text1, const char *text2=0, const char *text3=0)
Definition XrdSysError.hh:133
Definition XrdSysLogger.hh:53