~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/pbms/src/cslib/CSLog.cc

  • Committer: Brian Aker
  • Date: 2010-09-13 21:43:18 UTC
  • mto: (1768.2.1 trunk)
  • mto: This revision was merged to the branch mainline in revision 1770.
  • Revision ID: brian@tangent.org-20100913214318-b5tdvn64qvtvybnj
Use full path for opening up directory files when checking for types.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
 *
15
15
 * You should have received a copy of the GNU General Public License
16
16
 * along with this program; if not, write to the Free Software
17
 
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
 
17
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
18
 *
19
19
 * Original author: Paul McCullagh (H&G2JCtL)
20
20
 * Continued development: Barry Leslie
29
29
 
30
30
#include <string.h>
31
31
#include <time.h>
32
 
#include <stdarg.h>
33
 
#include <stdio.h>
34
 
#include <stdlib.h>
35
32
 
36
33
#include "CSLog.h"
37
34
#include "CSMemory.h"
39
36
#include "CSStrUtil.h"
40
37
#include "CSThread.h"
41
38
#include "CSGlobal.h"
42
 
 
43
 
 
44
 
//#ifdef DEBUG
45
 
//#define DEFAULT_LOG_BUFFER_SIZE                       10
46
 
//#else
47
 
#define DEFAULT_LOG_BUFFER_SIZE                 2000
48
 
//#endif
49
 
 
50
39
/*
51
40
 * The global logging object.
52
41
 */
171
160
        unlock();
172
161
}
173
162
 
174
 
void CSLog::log_va(CSThread *self, int level, const char *func, const char *file, int line, const char *fmt, va_list ap)
175
 
{
176
 
        char buffer[DEFAULT_LOG_BUFFER_SIZE];
177
 
        char *log_string = NULL;
178
 
 
179
 
        lock();
180
 
 
181
 
#if !defined(va_copy) || defined(OS_SOLARIS)
182
 
        int len;
183
 
 
184
 
        len = vsnprintf(buffer, DEFAULT_LOG_BUFFER_SIZE-1, fmt, ap);
185
 
        if (len > DEFAULT_LOG_BUFFER_SIZE-1)
186
 
                len = DEFAULT_LOG_BUFFER_SIZE-1;
187
 
        buffer[len] = 0;
188
 
        log_string = buffer;
189
 
#else
190
 
        /* Use the buffer, unless it is too small */
191
 
        va_list ap2;
192
 
 
193
 
        va_copy(ap2, ap);
194
 
        if (vsnprintf(buffer, DEFAULT_LOG_BUFFER_SIZE, fmt, ap) >= DEFAULT_LOG_BUFFER_SIZE) {
195
 
                if (vasprintf(&log_string, fmt, ap2) == -1)
196
 
                        log_string = NULL;
197
 
        }
198
 
        else
199
 
                log_string = buffer;
200
 
#endif
201
 
 
202
 
        if (log_string) {
203
 
                log(self, func, file, line, level, log_string);
204
 
 
205
 
                if (log_string != buffer)
206
 
                        free(log_string);
207
 
        }
208
 
 
209
 
        unlock();
210
 
}
211
 
 
212
 
void CSLog::logf(CSThread *self, int level, const char *fmt, ...)
213
 
{
214
 
        va_list ap;
215
 
 
216
 
        va_start(ap, fmt);
217
 
        log_va(self, level, NULL, NULL, 0, fmt, ap);
218
 
        va_end(ap);
219
 
}
220
 
 
221
 
void CSLog::logf(CSThread *self, int level, const char *func, const char *file, int line, const char *fmt, ...)
222
 
{
223
 
        va_list ap;
224
 
 
225
 
        va_start(ap, fmt);
226
 
        log_va(self, level, func, file, line, fmt, ap);
227
 
        va_end(ap);
228
 
}
 
163
 
229
164