2008-08-06 18:36:30 +00:00
|
|
|
// This file is part of BOINC.
|
2005-01-20 23:22:22 +00:00
|
|
|
// http://boinc.berkeley.edu
|
2008-08-06 18:36:30 +00:00
|
|
|
// Copyright (C) 2008 University of California
|
2004-08-05 21:42:27 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// BOINC is free software; you can redistribute it and/or modify it
|
|
|
|
// under the terms of the GNU Lesser General Public License
|
|
|
|
// as published by the Free Software Foundation,
|
|
|
|
// either version 3 of the License, or (at your option) any later version.
|
2005-01-20 23:22:22 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// BOINC is distributed in the hope that it will be useful,
|
2005-01-20 23:22:22 +00:00
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
// See the GNU Lesser General Public License for more details.
|
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
|
2004-08-05 21:42:27 +00:00
|
|
|
|
2017-04-08 06:54:49 +00:00
|
|
|
#ifndef BOINC_MSG_LOG_H
|
|
|
|
#define BOINC_MSG_LOG_H
|
2007-03-14 22:57:37 +00:00
|
|
|
|
2004-07-13 13:54:09 +00:00
|
|
|
#include <cstdio>
|
2004-04-07 06:51:42 +00:00
|
|
|
#include <cstdarg>
|
|
|
|
|
2004-08-05 21:42:27 +00:00
|
|
|
#ifdef _USING_FCGI_
|
2008-09-09 19:10:42 +00:00
|
|
|
#include "boinc_fcgi.h"
|
2004-08-05 21:42:27 +00:00
|
|
|
#endif
|
|
|
|
|
2004-04-07 06:51:42 +00:00
|
|
|
// the __attribute((format...)) tags are GCC extensions that let the compiler
|
|
|
|
// do like-checking on printf-like arguments
|
2004-04-08 08:15:23 +00:00
|
|
|
//
|
2004-04-07 06:51:42 +00:00
|
|
|
#if !defined(__GNUC__) && !defined(__attribute__)
|
|
|
|
#define __attribute__(x) /*nothing*/
|
|
|
|
#endif
|
|
|
|
|
2004-04-30 23:18:56 +00:00
|
|
|
#ifdef _USING_FCGI_
|
2008-02-05 20:16:57 +00:00
|
|
|
#define __attribute__(x) //nothing
|
2004-04-30 23:18:56 +00:00
|
|
|
#endif
|
|
|
|
|
2009-01-13 23:06:02 +00:00
|
|
|
#undef printf
|
|
|
|
#undef vprintf
|
|
|
|
|
2004-04-08 08:15:23 +00:00
|
|
|
class MSG_LOG {
|
2008-02-05 21:26:43 +00:00
|
|
|
public:
|
2004-04-07 06:51:42 +00:00
|
|
|
int debug_level;
|
2017-06-06 22:53:11 +00:00
|
|
|
int indent_level;
|
2004-04-07 06:51:42 +00:00
|
|
|
char spaces[80];
|
|
|
|
FILE* output;
|
2005-04-18 05:37:31 +00:00
|
|
|
int pid;
|
2004-04-07 06:51:42 +00:00
|
|
|
|
2004-04-08 08:15:23 +00:00
|
|
|
MSG_LOG(FILE* output);
|
2008-02-06 04:32:06 +00:00
|
|
|
virtual ~MSG_LOG(){}
|
|
|
|
|
2004-04-07 06:51:42 +00:00
|
|
|
void enter_level(int = 1);
|
|
|
|
void leave_level() { enter_level(-1); }
|
2004-04-08 08:15:23 +00:00
|
|
|
MSG_LOG& operator++() { enter_level(); return *this; }
|
|
|
|
MSG_LOG& operator--() { leave_level(); return *this; }
|
2004-04-07 06:51:42 +00:00
|
|
|
|
|
|
|
void printf(int kind, const char* format, ...) __attribute__ ((format (printf, 3, 4)));
|
|
|
|
void printf_multiline(int kind, const char* str, const char* prefix_format, ...) __attribute__ ((format (printf, 4, 5)));
|
|
|
|
void printf_file(int kind, const char* filename, const char* prefix_format, ...) __attribute__ ((format (printf, 4, 5)));
|
|
|
|
void vprintf(int kind, const char* format, va_list va);
|
|
|
|
void vprintf_multiline(int kind, const char* str, const char* prefix_format, va_list va);
|
|
|
|
void vprintf_file(int kind, const char* filename, const char* prefix_format, va_list va);
|
2017-06-06 22:53:11 +00:00
|
|
|
void set_debug_level(int new_level) { debug_level = new_level; }
|
|
|
|
void set_indent_level(int new_level);
|
|
|
|
|
2004-04-07 06:51:42 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
virtual const char* v_format_kind(int kind) const = 0;
|
|
|
|
virtual bool v_message_wanted(int kind) const = 0;
|
|
|
|
};
|
|
|
|
|
2004-04-08 08:15:23 +00:00
|
|
|
// automatically ++/--MSG_LOG on scope entry / exit.
|
|
|
|
// See lib/msg_log.C for commentary
|
|
|
|
//
|
2005-07-07 22:26:49 +00:00
|
|
|
#if _MSC_VER >= 1300
|
2020-05-06 22:30:32 +00:00
|
|
|
#pragma warning(push)
|
2005-07-07 22:26:49 +00:00
|
|
|
#pragma warning(disable: 4512) // assignment operator could not be generated
|
|
|
|
#endif
|
|
|
|
|
2004-04-08 08:15:23 +00:00
|
|
|
class SCOPE_MSG_LOG {
|
|
|
|
MSG_LOG& messages;
|
2004-04-07 06:51:42 +00:00
|
|
|
int kind;
|
|
|
|
public:
|
2004-04-08 08:15:23 +00:00
|
|
|
SCOPE_MSG_LOG(MSG_LOG& messages_, int kind_) : messages(messages_), kind(kind_)
|
2004-04-07 06:51:42 +00:00
|
|
|
{ ++messages; }
|
2004-04-08 08:15:23 +00:00
|
|
|
~SCOPE_MSG_LOG() { --messages; }
|
|
|
|
SCOPE_MSG_LOG& operator++() { ++messages; return *this; }
|
|
|
|
SCOPE_MSG_LOG& operator--() { --messages; return *this; }
|
2004-04-07 06:51:42 +00:00
|
|
|
|
|
|
|
void printf(const char* format, ...) __attribute__ ((format (printf, 2, 3)));
|
|
|
|
void printf_multiline(const char* str, const char* prefix_format, ...) __attribute__ ((format (printf, 3, 4)));
|
|
|
|
void printf_file(const char* filename, const char* prefix_format, ...) __attribute__ ((format (printf, 3, 4)));
|
|
|
|
};
|
|
|
|
|
2005-07-07 22:26:49 +00:00
|
|
|
#if _MSC_VER >= 1300
|
2020-05-06 22:30:32 +00:00
|
|
|
#pragma warning(pop)
|
2005-07-07 22:26:49 +00:00
|
|
|
#endif
|
|
|
|
|
2012-08-03 00:49:07 +00:00
|
|
|
#ifdef _USING_FCGI_
|
|
|
|
#undef __attribute__
|
|
|
|
#endif
|
|
|
|
|
2007-03-14 22:57:37 +00:00
|
|
|
#endif
|