desktop: TaskEdit: make recur end date "recent" too, when activated
[barry/progweb.git] / src / log.cc
blob18a49443609d145ae0507cbd64417be114ad3831
1 ///
2 /// \file log.cc
3 /// General Barry interface routines
4 ///
6 /*
7 Copyright (C) 2008-2012, Net Direct Inc. (http://www.netdirect.ca/)
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 See the GNU General Public License in the COPYING file at the
19 root directory of this project for more details.
22 #include "log.h"
23 #include "clog.h"
24 #include <pthread.h>
25 #include <stdio.h>
26 #include <stdarg.h>
27 #include <string.h>
28 #include <iostream>
30 namespace Barry {
32 extern bool __data_dump_mode__;
33 extern std::ostream *LogStream;
34 extern pthread_mutex_t LogStreamMutex;
36 LogLock::LogLock()
38 while( pthread_mutex_lock(&LogStreamMutex) != 0 )
42 LogLock::~LogLock()
44 pthread_mutex_unlock(&LogStreamMutex);
48 bool LogVerbose()
50 return __data_dump_mode__;
53 std::ostream* GetLogStream()
55 return LogStream;
58 } // namespace Barry
60 // Callable from C:
62 void BarryLogf(int verbose, const char *msg, ...)
64 va_list vl;
65 va_start(vl, msg);
66 char buffer[2048];
67 char *output = buffer;
68 int buflen = sizeof(buffer);
69 int n = vsnprintf(buffer, buflen, msg, vl);
70 if( n < 0 || n >= buflen ) {
71 buflen = n + 100;
72 output = new char [buflen];
73 n = vsnprintf(output, buflen, msg, vl);
74 if( n < 0 || n >= buflen ) {
75 delete [] output;
76 output = buffer;
77 strcpy(buffer, "BarryLog: (trace error, output too long for buffer)");
80 va_end(vl);
82 if( verbose ) {
83 barryverbose(output);
85 else {
86 barrylog(output);
89 if( output != buffer )
90 delete [] output;