Dlf.hpp 8.06 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/******************************************************************************
 *                      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.
 *
20
 * @(#)$RCSfile: Dlf.hpp,v $ $Revision: 1.12 $ $Release$ $Date: 2009/08/18 09:42:51 $ $Author: waldron $
21
22
23
24
25
26
 *
 * C++ interface to DLF
 *
 * @author Sebastien Ponce
 *****************************************************************************/

27
#ifndef DLF_DLF_WRITE_HPP
28
29
30
#define DLF_DLF_WRITE_HPP 1

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

37
/**
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
 * 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.
53
54
 */
#define CASTOR_DLF_WRITEPC(uuid, severity, message_no, params) \
55
  castor::dlf::dlf_writepc( \
56
57
58
59
60
61
62
63
    __FILE__, \
    __LINE__, \
    __PRETTY_FUNCTION__, \
    uuid, \
    severity, \
    message_no, \
    params)

64
65
66
67
namespace castor {

  namespace dlf {

68
69
70
71
72
73
74
75
76
    /**
     * 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();

77
78
79
    /**
     * Initialization of the DLF logging system
     * @param facilityName name of the DLF facility to use
80
     * @param messages array of messages to declare in the
81
82
     * facility. The end of the array is marked by a
     * message with negative number.
83
     * @param throws a CASTOR exception in case of failure
84
     */
85
    void dlf_init(const char* facilityName,
86
87
                  Message messages[])
      throw (castor::exception::Exception);
88

89
    /**
90
91
92
93
94
95
96
     * 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.
97
98
99
100
101
102
103
     * @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,
104
                         Message messages[]) throw();
105

106
    /**
107
108
109
     * 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.
110
111
112
113
114
115
116
117
118
119
120
121
122
     * @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,
123
                     struct Cns_fileid *ns_invariant = 0) throw();
124
125

    /**
126
127
128
129
130
     * 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 n>
131
132
133
134
135
    void dlf_writep (Cuuid_t uuid,
                     int severity,
                     int message_no,
                     castor::dlf::Param (&params)[n],
                     struct Cns_fileid *ns_invariant = 0) throw() {
136
137
138
139
140
141
      dlf_writep(uuid, severity, message_no, n, params, ns_invariant);
    }

    /**
     * prints a message together with the context information file, line and
     * function into dlf. Note that no exception will ever
142
143
     * be thrown in case of failure. Failures will actually be silently
     * ignored in order to not impact the processing.
144
145
146
     * @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.
147
148
149
150
151
152
153
154
     * @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.
     */
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
    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.
     */
170
    template<int n>
171
172
173
174
175
176
177
178
    void dlf_writepc (const char *file,
                      const int line,
                      const char *function,
                      Cuuid_t uuid,
                      int severity,
                      int message_no,
                      castor::dlf::Param (&params)[n],
                      struct Cns_fileid *ns_invariant = 0) throw() {
179
      dlf_writepc(file, line, function, uuid, severity, message_no, n, params,
180
                  ns_invariant);
181
    }
182

183
    /**
184
185
186
187
188
189
190
191
192
193
194
195
196
     * 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
     */
197
    void dlf_writep (Cuuid_t uuid,
198
199
                     int severity,
                     int message_no,
200
                     u_signed64 fileId,
201
202
203
204
205
                     std::string nsHost,
                     int numparams = 0,
                     castor::dlf::Param params[] = 0) throw();

  } // end of namespace dlf
206
207
208
209
210

} // end of namespace castor


#endif // DLF_DLF_WRITE_HPP