Dlf.hpp 9.26 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/******************************************************************************
 *                      dlf_write.hpp
 *
 * This file is part of the Castor project.
 * See http://castor.web.cern.ch/castor
 *
 * Copyright (C) 2003  CERN
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *
 *
 * C++ interface to DLF
 *
 * @author Sebastien Ponce
 *****************************************************************************/

26
#ifndef DLF_DLF_WRITE_HPP
27
28
29
#define DLF_DLF_WRITE_HPP 1

// Include Files
30
#include "dlf_api.h"
31
32
#include "castor/dlf/Message.hpp"
#include "castor/dlf/Param.hpp"
33
34
#include "castor/exception/Exception.hpp"
#include <vector>
35

36
/**
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
 * Logs a message and adds the context information of file, line and function
 * as three parameters of the message.
 */
#define CASTOR_DLF_WRITEC(uuid, severity, message_no) \
  castor::dlf::dlf_writepc( \
    __FILE__, \
    __LINE__, \
    __PRETTY_FUNCTION__, \
    uuid, \
    severity, \
    message_no)

/**
 * Logs a message with a set of parameters and automatically generates and
 * adds the context information of file, line and function to the parameters.
52
53
 */
#define CASTOR_DLF_WRITEPC(uuid, severity, message_no, params) \
54
  castor::dlf::dlf_writepc( \
55
56
57
58
59
60
61
62
    __FILE__, \
    __LINE__, \
    __PRETTY_FUNCTION__, \
    uuid, \
    severity, \
    message_no, \
    params)

63
64
65
66
namespace castor {

  namespace dlf {

67
68
69
70
71
72
73
74
    /**
     * Vector of messages that should be declared
     * at initialization. These messages were sent to
     * dlf_addMessage before it was initialized and
     * thus have to wait here.
     */
    std::vector<std::pair<int, castor::dlf::Message*> >&
    dlf_getPendingMessages() throw();
75
76
77
78
79
80
81
 
    /**
     * Helper class adding a cleanup for unclaimed pending
     * messages. This is for the case when dlf_init never gets
     * called (new done in castor::dlf::dlf_addMessages for 
     * static data from castorclient (?) library.
     */
82
    class PendingMessagesVector: 
83
84
    public std::vector<std::pair<int, castor::dlf::Message*> > {
    public:
85
      ~PendingMessagesVector() {
86
87
88
89
90
91
92
93
94
        for (std::vector<std::pair<int, Message*> >::iterator it =
               dlf_getPendingMessages().begin();
             it != dlf_getPendingMessages().end();
             it++) {
          delete[](it->second);
          it->second = NULL;
        }
      }
    };
95

96
97
98
    /**
     * Initialization of the DLF logging system
     * @param facilityName name of the DLF facility to use
99
     * @param messages array of messages to declare in the
100
101
     * facility. The end of the array is marked by a
     * message with negative number.
102
     * @param throws a CASTOR exception in case of failure
103
     */
104
    void dlf_init(const char* facilityName,
105
106
                  Message messages[])
      throw (castor::exception::Exception);
107

108
    /**
109
110
111
112
113
114
115
     * Adds messages to the current DLF facility.
     * This method can be called before the initialization of DLF
     * if needed. In such a case, the messages will be stored
     * and added at initialization time.
     * Note that no exception will ever be thrown in case of failure.
     * Failures will actually be silently ignored in order to not
     * impact the processing.
116
117
118
119
120
121
122
     * @param offset the offset to add to each message number.
     * This is to avoid collisions with previously added messages
     * @param messages array of messages to decalre in the
     * facility. The end of the array is marked by a
     * message with negative number.
     */
    void dlf_addMessages(int offset,
123
                         Message messages[]) throw();
124

125
    /**
126
127
128
     * prints a message into dlf. Note that no exception will ever
     * be thrown in case of failure. Failures will actually be silently
     * ignored in order to not impact the processing.
129
130
131
132
133
134
135
136
137
138
139
140
141
     * @param uuid the uuid of the component issuing the message
     * @param message_no the message number in the facility.
     * @param severity the severity of the message.
     * @param numparams the number of parameters in the message
     * @param params the parameters of the message, given as an array
     * @ns_invariant the castor file concerned by the message
     * (if any), given as a name server fileId.
     */
    void dlf_writep (Cuuid_t uuid,
                     int severity,
                     int message_no,
                     int numparams = 0,
                     castor::dlf::Param params[] = 0,
142
                     struct Cns_fileid *ns_invariant = 0) throw();
143
144

    /**
145
146
147
148
     * A template function that wraps dlf_writep in order to get the compiler
     * to automatically determine the size of the params parameter, therefore
     * removing the need for the devloper to provide it explicity.
     */
149
    template<int numparams>
150
151
152
    void dlf_writep (Cuuid_t uuid,
                     int severity,
                     int message_no,
153
                     castor::dlf::Param (&params)[numparams],
154
                     struct Cns_fileid *ns_invariant = 0) throw() {
155
      dlf_writep(uuid, severity, message_no, numparams, params, ns_invariant);
156
157
158
159
160
    }

    /**
     * prints a message together with the context information file, line and
     * function into dlf. Note that no exception will ever
161
162
     * be thrown in case of failure. Failures will actually be silently
     * ignored in order to not impact the processing.
163
164
165
     * @param file the name of the file where dlf_writepc was called.
     * @param line the number of the line where dlf_writepc was called.
     * @param function the name of the function where dlf_writepc was called.
166
167
168
169
170
171
172
173
     * @param uuid the uuid of the component issuing the message
     * @param message_no the message number in the facility.
     * @param severity the severity of the message.
     * @param numparams the number of parameters in the message
     * @param params the parameters of the message, given as an array
     * @ns_invariant the castor file concerned by the message
     * (if any), given as a name server fileId.
     */
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
    void dlf_writepc (const char *file,
                      const int line,
                      const char *function,
                      Cuuid_t uuid,
                      int severity,
                      int message_no,
                      int numparams = 0,
                      castor::dlf::Param params[] = 0,
                      struct Cns_fileid *ns_invariant = 0) throw();

    /**
     * A template function that wraps dlf_writepc in order to get the compiler
     * to automatically determine the size of the params parameter, therefore
     * removing the need for the devloper to provide it explicity.
     */
189
    template<int numparams>
190
191
192
193
194
195
    void dlf_writepc (const char *file,
                      const int line,
                      const char *function,
                      Cuuid_t uuid,
                      int severity,
                      int message_no,
196
                      castor::dlf::Param (&params)[numparams],
197
                      struct Cns_fileid *ns_invariant = 0) throw() {
198
199
      dlf_writepc(file, line, function, uuid, severity, message_no, numparams,
        params, ns_invariant);
200
    }
201

202
    /**
203
204
205
206
207
208
209
210
211
212
213
214
215
     * wrapper to dlf_writte but it compounds the struct Cns_fileId
     * ns_invariantfrom the prints a message into dlf. Note that no
     * exception will ever
     * be thrown in case of failure. Failures will actually be silently
     * ignored in order to not impact the processing.
     * @param uuid the uuid of the component issuing the message
     * @param message_no the message number in the facility.
     * @param severity the severity of the message.
     * @param numparams the number of parameters in the message
     * @param params the parameters of the message, given as an array
     * @param fileId the castor file id
     * @param nsHost the name server
     */
216
    void dlf_writep (Cuuid_t uuid,
217
218
                     int severity,
                     int message_no,
219
                     u_signed64 fileId,
220
221
222
223
                     std::string nsHost,
                     int numparams = 0,
                     castor::dlf::Param params[] = 0) throw();

224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
    /**
     * A template function that wraps dlf_writep in order to get the compiler
     * to automatically determine the size of the params parameter, therefore
     * removing the need for the devloper to provide it explicity.
     */
    template<int numparams>
    void dlf_writep (Cuuid_t uuid,
                     int severity,
                     int message_no,
                     u_signed64 fileId,
                     std::string nsHost,
                     castor::dlf::Param (&params)[numparams]) throw() {
      dlf_writep(uuid, severity, message_no, fileId, nsHost, numparams,
        params);
    }

240
  } // end of namespace dlf
241
242
243
244
245

} // end of namespace castor


#endif // DLF_DLF_WRITE_HPP