Added LTLIBINTL and LTLIBICONV to tools/Makefile.am
[barry.git] / src / log.cc
blob5b25a48296220152052e06be5e835128f369f65c
1 ///
2 /// \file log.cc
3 /// General Barry interface routines
4 ///
6 /*
7 Copyright (C) 2008-2010, 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 int n = vsnprintf(buffer, sizeof(buffer), msg, vl);
68 va_end(vl);
69 if( n > -1 && n < (int)sizeof(buffer) )
70 strcpy(buffer, "BarryLog: (trace error, output too long for buffer)");
72 if( verbose ) {
73 barryverbose(buffer);
75 else {
76 barrylog(buffer);